Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP eats linefeed in php/plaintext mixed mode

Tags:

text

php

This one is bothering me for a while. Let's say we have a simple PHP-File:

Line 0
Line 1
<?="Line 2"?>
Line 3

Processing this file will result in:

Line 0
Line 1
Line 2Line 3

Where did the line feed after ?> go? The linefeed is not beeing devoured when placing some character after the closing tag (e.g. ?>.).

Is there a way to control this behaviour? I'm not willing to place whitespaces after the closing tag, because my IDE is configured to remove whitespaces before linefeeds (and I like it that way).

like image 459
Felix Wessendorf Avatar asked Jan 23 '13 15:01

Felix Wessendorf


Video Answer


1 Answers

Yes, indeed:

The closing tag for the block will include the immediately trailing newline if one is present.

http://php.net/manual/en/language.basic-syntax.instruction-separation.php

Meaning, if the ?> is the last thing on the line, the newline will be removed as part of the closing PHP block. You need to explicitly echo a newline or add an additional newline.

like image 165
deceze Avatar answered Sep 18 '22 03:09

deceze