|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-05-04 10:29 UTC] fantasticjamieburns at hotmail dot com
Description: ------------ Well when I eval() or include() the code below, a newline gets truncated. Basically, whenerver an "end of php block" is the last thing on a line, the parser steals a newline. Reproduce code: --------------- ONE TWO<?php /* whatever */ ?> THREE Expected result: ---------------- ONE TWO THREE Actual result: -------------- ONE TWOTHREE PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 20 09:00:02 2025 UTC |
OK, thanks for classifying this as a documentation problem. If it is indeed the case that a PHP end tag considers a newline to be "part of the end tag" then I must say that is really dumb. It breaks all sorts of simple things like: <pre> - <?php echo("jack"); ?> - <?php echo("jill"); ?> </pre> Now why on earth would PHP think it has the right to take away a newline character OUTSIDE of the end tag? In every other case the end tag finishes with the less-than symbol, no? Now, if a newline is now part of the close tag, why not a space? <?php echo('jack'); ?> <?php echo("jill"); ?> Does the space now also get taken by PHP? Or is it outside the PHP blocks? And if it is outside, is it not because it is beyone the less-than symbol of the first block?Thanks for taking the time to look at this anyway. For anyone else reading this in the future and thinking this is crazy behaviour this quickly gets around it for evaluated code: $source = preg_replace('#<\?php (.*?) \?>\n#', "<?php \\1 ?>\n\n", $source); $source = preg_replace('#<\?php (.*?) \?>\r\n#', "<?php \\1 ?>\r\n\r\n", $source); :o)