ID: 26427
Updated by: [EMAIL PROTECTED]
Reported By: phpbug at lapage dot com
-Status: Assigned
+Status: Bogus
Bug Type: Filesystem function related
Operating System: Win98
PHP Version: 4.3.2
Assigned To: wez
New Comment:
I didn't invent DOS, so I'm not the father of this mode ;-)
When you activate text-mode translation, the MS libc will convert \n
into \r\n as you write to the file.
If you save your PHP script using DOS line endings, each line of a
heredoc will end with \r\n characters (as that is what appears in the
file). If you write that to a file opened in text-mode, \r\n will be
translated into \r\r\n as you have observed.
If you save your PHP script using UNIX line endings, then
each line of the heredoc will end with a single \n, and will be written
to the file using \r\n.
So, what is the solution?
Be explicit; open the file in binary mode (the default now in 4.3.x),
and write the required line endings yourself using \r\n explicitly (or
implicitly by using a heredoc and a PHP script saved using DOS line
endings).
Since this is expected behaviour and not really a bug, I'm marking this
report as Bogus.
Previous Comments:
------------------------------------------------------------------------
[2003-11-27 01:01:01] [EMAIL PROTECTED]
Assigned to the father of this mode..
------------------------------------------------------------------------
[2003-11-26 11:06:28] phpbug at lapage dot com
Description:
------------
Writing in text-mode does not play nicely with heredoc, in Win32. Line
endings become \r\r\n in the typical situation: php source code with
\r\n endings.
This will break, for example, batch files written for Win98.
Reproduce code:
---------------
$fp= fopen('file.txt', 'wt');
fwrite($fp, <<<ENDTEXT
One line of text
Another line of text
Last line of text\n
ENDTEXT
);
fclose($fp);
Expected result:
----------------
One line of text\r\n
Another line of text\r\n
Last line of text\r\n
Actual result:
--------------
One line of text\r\r\n
Another line of text\r\r\n
Last line of text\r\n
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26427&edit=1