#23406 [Asn->Fbk]: \r\n not functioning the same from 4.3.1 and prior

From: Date: Wed, 30 Apr 2003 11:24:15 +0000
Subject: #23406 [Asn->Fbk]: \r\n not functioning the same from 4.3.1 and prior
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-38821@lists.php.net to get a copy of this message
ID: 23406 Updated by: wez@php.net Reported By: gfraley5 at earthlink dot net -Status: Assigned +Status: Feedback Bug Type: Filesystem function related Operating System: Win98SE,WinXP,Win2K PHP Version: 4.3.2RC2 Assigned To: wez New Comment: I can't reproduce this here (tried 4.2.1 and 4.3.2 under XP). NOTE: readfile() returns the number of bytes it wrote, NOT the contents of the file. Use file_get_contents() for that. Please try this script on 4.3.2 and your 4.2.3 and report back (paste the output from each into this report): <?php $myArray[] = 'msgid'."\r\n"; $myArray[] = '1049987091'."\r\n"; $myArray[] = '1050930128'."\r\n"; $l = 0; $fp = fopen("problemFile.php",'w') or die("Unable to open file"); for ($i=0;$i<count($myArray);$i++) { if ($i==0) { $prefx = "<? Header(\"HTTP/1.0 403 Forbidden\");exit;?>\r\n"; } else { $prefx = ""; } $l += fwrite($fp, $prefx.$myArray[$i]); } fclose($fp); echo "Wrote: $l bytes; filesize is now " . filesize("problemFile.php") . "\n"; echo "==== using readfile =====\n"; $x = readfile("problemFile.php"); echo "==== readfile read $x bytes ====\n"; echo "==== using fopen 'r' ===\n"; $fp = fopen("problemFile.php", "r"); while (!feof($fp)) { echo fgets($fp); } fclose($fp); echo "==== using fopen 'rb' ===\n"; $fp = fopen("problemFile.php", "rb"); while (!feof($fp)) { echo fgets($fp); } fclose($fp); echo "==== done ===\n"; ?> Previous Comments: ------------------------------------------------------------------------ [2003-04-30 05:57:42] sniper@php.net Wez: You broke it, fix it before 4.3.2 goes gold. (some streams stuff :) ------------------------------------------------------------------------ [2003-04-29 16:34:34] gfraley5 at earthlink dot net It works _perfectly_ under 4.2.3 WITHOUT using 'wb', just like 4.3.1! That's the problem :(. I always upgrade before the finals are released and it has always worked as just 'w'. Not only that, and hold on here, but the windows version has NEVER required \r\n. It always works with \n but that's a whole 'nother issue :) ------------------------------------------------------------------------ [2003-04-29 16:02:19] michael dot mauch at gmx dot de <http://www.php.net/downloads.php> (scroll down to where it says "PHP 4.2.3"). ------------------------------------------------------------------------ [2003-04-29 14:24:35] gfraley5 at earthlink dot net Where can I get the older version? ------------------------------------------------------------------------ [2003-04-29 09:34:19] wez@php.net The curious thing is that PHP doesn't treat the line endings specially itself. Can you try this with 4.2.3 (NOT 4.3.2!)? It's more likely that this was a bug in 4.3.0/4.3.1 that has been fixed; I do want to get to the bottom of it though. In general, it is always a good idea to use the 'b' flag in your fopen calls if you are planning to write canonical line endings, as windows does strange things with line endings on text-mode file handles. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/23406 -- Edit this bug report at http://bugs.php.net/?id=23406&edit=1

« previous php.bugs (#38821) next »