php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23296 Writing lines to file breaks new line separation
Submitted: 2003-04-21 09:09 UTC Modified: 2003-04-21 12:39 UTC
From: gfraley5 at earthlink dot net Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.2RC1 OS: WinXP, Win2k
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gfraley5 at earthlink dot net
New email:
PHP Version: OS:

 

 [2003-04-21 09:09 UTC] gfraley5 at earthlink dot net
This works in 4.3.1 and prior but does not work in 4.3.2RC's and current CVS.

<?
$myArray[] = 'msgid'."\n";
$myArray[] = '1049987091'."\n";
$myArray[] = '1050930128'."\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; ?>\n";
	else $prefx = "";
	fwrite($fp,$prefx.$myArray[$i]);
}
	fclose($fp);
?>

The file looks like this, which is correct:
<? Header("HTTP/1.0 403 Forbidden");exit; ?>
msgid
1049987091
1050930128

However, under 4.3.2 the file looks like this:
<? Header("HTTP/1.0 403 Forbidden");exit; ?>
msgid1049987091
1050930128

If you modify the code to this, moving the header code to the array, it works under 4.3.2:
<?
$myArray[] = "<? Header(\"HTTP/1.0 403 Forbidden\");exit; ?>\n";
$myArray[] = 'msgid'."\n";
$myArray[] = '1049987091'."\n";
$myArray[] = '1050930128'."\n";

$fp = fopen("problemFile.php",'w') or die("Unable to open file");
for ($i=0;$i<count($myArray);$i++) {
	fwrite($fp,$myArray[$i]);
	echo nl2br($myArray[$i]);
}
	fclose($fp);
?>

The file is correct.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-21 09:37 UTC] sniper@php.net
Can not reproduce with latest stable CVS snapshot on linux.

 [2003-04-21 09:45 UTC] gfraley5 at earthlink dot net
My mistake.  It is not working on Win32.
 [2003-04-21 09:54 UTC] sniper@php.net
Can not reproduce in win2k using latest STABLE snapshot.
(and windows expects \r\n as line-end)

 [2003-04-21 10:27 UTC] gfraley5 at earthlink dot net
I just pulled the latest win32 package and it does not work on XP or win2k.  It fails 100% of the time.  It works 100% of the time when I reinstall 4.3.1.  Here is the link I am pulling the latest snap from http://snaps.php.net/win32/php4-win32-STABLE-200304210830.zip. If this is correct, then the code does not work.  Also, as to the \n or \r\n.  \n is working 100% of the time, on Windows, on php4.3.1 and prior.  The fact that I can go on 2 different versions of windows in 2 different locations and reproduce this validates the test, imo.  The win2k version I am using is 5.00.2195.
 [2003-04-21 12:29 UTC] sniper@php.net
I can _NOT_ reproduce this. (and \r\n is the only correct line-ending in windows/dos)

 [2003-04-21 12:39 UTC] gfraley5 at earthlink dot net
Regardless, it does not work and \n does work in windows.
 [2003-04-29 08:21 UTC] jerry at reininger dot org
This is a bug and I too have been able to reproduce it like Gaylen has said, even on a Windows 98SE box.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 21:01:36 2024 UTC