php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8579 text files do not have \r\n translation from \n
Submitted: 2001-01-07 14:11 UTC Modified: 2001-10-29 02:21 UTC
From: dpfender at innova dot net Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.0.4 OS: windows 2000 Pro, IIS 5
Private report: No CVE-ID: None
 [2001-01-07 14:11 UTC] dpfender at innova dot net
C programs that execute on Windows systems use fopen() with
a "b" mode option (example, fopen(fname,"wb")) when the
output string is to be written exactly as is to the file.
When opened with "w", the '\n' character is automatically
translated to the sequence '\r\n'.  This character sequence
defines the end of lines to Windows-based text programs,
such as Notepad.  This capability is not supported with PHP
though the documentation hints that it should.  Without this
feature, PHP programs are not directly portable between
Windows systems and Unix/Linux systems without a lot of
special program coding on the part of the developer.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-08 14:04 UTC] stas@php.net
fopen uses whatever mode you give it. The rest of functions
(like "system") use 'b' modes, since they are meant to pass
the data unchanged. If you have a code that uses fopen and
it ignores 'b', please reopen the report and post the code,
otherwise - you are getting the intended behaviour.
 [2001-01-08 20:33 UTC] dpfender at innova dot net
The problem is not with fopen(file, "wb"), which works 
correctly.  The problem is with fopen(file, "w") because
it works the same as the "wb" option.  Using the "w" option
should cause any text to be translated from '\n' to '\r\n'
on Windows systems or else text editors such as Notepad
will not view the file correctly.
 [2001-01-25 18:37 UTC] joey@php.net
This is not really a bug. PHP emulates C in this, as it does
in many other things. It seems that in the opinion of most
of the developers, this is a Good Thing (tm).

Reclassify as a Change Request.
 [2001-01-25 19:22 UTC] joey@php.net
Cynic pointed out that I was misreading this bug report.
PHP's fwrite doesn't seem to do the same translation that
C does on windows boxes.
 [2001-10-29 02:21 UTC] sniper@php.net
PHP uses the system provided fwrite. If that does not
work, it's not PHP problem. 

--Jani

 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Feb 07 23:03:39 2023 UTC