8

PHP enters html-mode if there are no php tags. That's simple enough. This code:

<pre>a
<?php echo 'b';?>
c
</pre>

Will output:

a
bc

The new line after <?php echo 'b';?> is trimmed.
But this code (space after closing php tag):

<pre>a
<?php echo 'b';?> 
c
</pre>

Will output:

a
b           // there is a space after 'b '
c

So, is the new line after last php tag always trimmed? Are there any other hidden trimming, formatting or some automatic stuff going on?


Edit: Today I have learned new definition of php tags:

PHP ending tag is ?> with an optional newline.

Feel free to broaden the answer if php tags have any other hidden/magic/auto properties.

3
  • 2
    look this PHP.net. "This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script." Commented Apr 1, 2014 at 20:34
  • Actually no! If you are gonna quote something you must quote it ALL: "If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file." and then goes your quotation. But yes, I have already read that. My question is about auto trim of first \n and are there any other hidden auto trimming or so.
    – CoR
    Commented Apr 1, 2014 at 21:20
  • This is documented clearly at The history of PHP eating newlines after the closing tag Commented Apr 2, 2014 at 12:29

0

Browse other questions tagged or ask your own question.