NYCPHP Meetup

NYPHP.org

[nycphp-talk] Closing Tags or Not Closing Tags, that is my question...

Gary Mort bz-gmort at beezifies.com
Tue Dec 18 10:59:29 EST 2007


David Krings wrote:
> Gary Mort wrote:
>> And since there are some operating systems where some editors will 
>> stick a blank space at the end of a file accidentally, not placing 
>> the closing ?> on the file means if some extra spaces/lines get added 
>> to the end of the file, they are not treated as HTML.
>
> Thanks for explaining, but I wonder why the </html> tag doesn't take 
> care of that. Once the html tag is closed anything after that ought to 
> be ignored by a browser. That is not the case?

The discussing is regarding the PHP interpreter, not the browser.

The problem is dealing with HTML data sent from the script to the 
browser.  The data is, for convenience and simplicity, in 2 parts.  The 
"header" data and the "content" - header here does not mean the HTML 
header section, but the actual header(where you send cookies and other 
information).

When sending data from a server to a client, all the header information 
has to come /before/ the content.

When your including say...12 different files into a page, sometimes 
script number 8 needs to send header information.  So the practice is to 
accumulate all the content information into a variable, and send that at 
the end of the script.

This makes it no longer possible to mix HTML and PHP code in a 
document(ok, it's possible, but outside the scope of this email) as the 
second you have a raw HTML outside the PHP execution tags, you have lost 
your chance of sending header data and are into the sending of body data.

The problem is when at the end of a file you place ?>[space]

The PHP interpreter sees that there is a charector after the ?> and 
sends it.  So now content has begun and you can no longer send headers.

Of course, that is less ugly than the
?> <?

Mistake, with a space between the two(less ugly because at least at the 
end of the file you can blame the editor!  In the middle of the file 
it's purely your fault, and why did you close and open the PHP execution 
tag to begin with!?)




More information about the talk mailing list