|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-11-21 20:15 UTC] php at 3wheel dot net
This problem never shows up when using PHP to output HTML since it ignores newlines... but if you're outputting straight text it's a huge hassle. Any block of php code placed at the end of a line (adjacent to a newline character) will "eat" that newline character. Example: ********10<? ?> ********20 Give it a try, it outputs: ********10********20 No matter what is present in the php block this happens. If there is a character directly following the block it will not get eaten: ********10<? ?>C ********20 Produces: ********10C ********20 This is a big annoyance for me, as I'm using PHP to generate text (as well as html) emails using templates. I'm thinking the parser is just running off the end of the line looking for another php block, but it never bothers to put the newline back when it's done. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 14:00:01 2025 UTC |
I have read the php documentation more times than I care to count, and I have read the bug sumission guidlines. I've also searched the documentation, the source, php.net, usenet, and Google to attempt to find any documentation or references as to why PHP would be removing newlines that it shouldn't be. Could you please clarify why this is not a bug? I urge you to reread my original submission, as well as my clarification below. I am NOT talking about HTML breaks, I am talking about newline (\n) characters. This ticket has nothing to do with HTML output, it's just text processing. Yes, I do understand how HTML breaks work. Here's an HTML example anyways, if that helps: -----cut here----- <html> <body> <pre> this is on two lines this should also be<? ?> on two lines </pre> this is on two lines,<br><? ?> but somebody stole my \n </body> </html> -----cut here----- Run from the command line, this produces: bash-2.04$ php test.php X-Powered-By: PHP/4.2.2 Content-type: text/html <html> <body> <pre> this is on two lines this should also beon two lines </pre> this is on two lines,<br>but somebody stole my \n </body> </html> Or another example: -----cut here----- <? ob_start(); ?> line1 line2<? ?> line3<? ?> line4 <? $lines = ob_get_contents(); ob_end_clean(); $lines = preg_replace("/\n/","NEWLINE\n",$lines); print $lines; ?> -----cut here----- The output of this one SHOULD be: NEWLINE line1NEWLINE line2NEWLINE line3NEWLINE line4NEWLINE NEWLINE (each line separated by a newline character) BUT.. the actual output is: NEWLINE line1NEWLINE line2line3line4NEWLINE NEWLINE The newlines that were present in the source file have mysteriously dissappeared after lines 2 and 3. I have also tested this under 4.2.3, and the bug is still present.