Last Updated: October 11, 2021
·
1.476K
· mauris

Write PHP scripts without ?>

It is good practice that all PHP files should have only one opening <?php and the rest of the file is defined to be only PHP. If you need to render HTML, put that into another file and use your PHP script to render that HTML file instead.

This reduces problems such as ghost whitespaces causing "Output already written before header" errors.

2 Responses
Add your response

I knew it was a good practice but I didn't know why. Thanks for sharing.

over 1 year ago ·

It also keeps your functionality clean from the presentation... Much like how one should NEVER write inline CSS, always keep your styling out of your HTML. For the love of god.

I opened an ASP file today that had all the HTML in the top, then all the jquery in the last 1000 lines. Inline CSS ever'where... I had to open it because the developer couldnt figure out why she was getting errors... blink

over 1 year ago ·