#20556 [Bgs->Opn]: php blocks strip newlines from output

From: Date: Fri, 22 Nov 2002 17:56:02 +0000
Subject: #20556 [Bgs->Opn]: php blocks strip newlines from output
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-25589@lists.php.net to get a copy of this message
ID: 20556 User updated by: php@3wheel.net Reported By: php@3wheel.net -Status: Bogus +Status: Open Bug Type: Output Control Operating System: FreeBSD 4.2-REL -PHP Version: 4.2.2 +PHP Version: 4.2.2 and 4.2.3 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2002-11-22 05:00:29] derick@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php ------------------------------------------------------------------------ [2002-11-21 20:15:52] php@3wheel.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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=20556&edit=1

« previous php.bugs (#25589) next »