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

From: Date: Tue, 29 Apr 2003 14:34:19 +0000
Subject: #23406 [Opn->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-38720@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: Open +Status: Feedback Bug Type: Filesystem function related Operating System: Win98SE,WinXP,Win2K PHP Version: 4.3.2RC2 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2003-04-29 09:27:02] gfraley5 at earthlink dot net Adding the 'wb' corrects the problem. But, and here is the most important issue, the behavior HAS changed from 4.3.1 and prior to 4.3.2 and it definitely breaks and renders useless the file that it writes out, based on how the input routines then read that file in 4.3.1 and prior. If you use \n instead of \r\n you have the same issue except the you don't get the line feed extra line. I did check the actual line endings and they are different and the byte count is different also. My ini settings have not changed. Can you explain why this change in behaviour has been made? Thanks. ------------------------------------------------------------------------ [2003-04-29 09:12:05] wez@php.net fopen("problemFile.php",'wb') Does that help? Also, check the line endings in the actual file (not in the output generated by php), and your auto_detect_line_endings ini setting. ------------------------------------------------------------------------ [2003-04-29 08:03:35] gfraley5 at earthlink dot net This code snippet demonstrates the problem. Under 4.3.1 and prior, it functions correctly. Under 4.3.2 (all versions) it does not function the same and is actually wrong. <? $myArray[] = 'msgid'."\r\n"; $myArray[] = '1049987091'."\r\n"; $myArray[] = '1050930128'."\r\n"; $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 = ""; fwrite($fp,$prefx.$myArray[$i]); } fclose($fp); echo nl2br(readfile("problemFile.php")); ?> Under 4.3.1 and prior, here is the output of problemFile.php: <? Header("HTTP/1.0 403 Forbidden");exit;?> msgid 1049987091 1050930128 Under 4.3.2, here is the output of problemFile.php. Notice the difference in the behaviour of the \r\n: <? Header("HTTP/1.0 403 Forbidden");exit;?> msgid 1049987091 1050930128 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23406&edit=1

« previous php.bugs (#38720) next »