ID:               26427
 User updated by:  phpbug at lapage dot com
 Reported By:      phpbug at lapage dot com
 Status:           Bogus
 Bug Type:         Filesystem function related
 Operating System: Win98
 PHP Version:      4.3.2
 Assigned To:      wez
 New Comment:

The point of text-mode is to avoid that sort of workaround, and to make
the code portable.

Here are some more arguments:

1. It's easy to fix in the php code.  Before translating \n to \r\n,
delete all \r.

2. It's a problem that's hard to notice at first for the general user. 
You wouldn't see the extra \r until it bit you (extra lines in ftp
upload; batch file won't work, etc.).

3. Binary mode may be default, but text-mode should be text-mode.

4. Saving a php file with unix line endings while working in dos is not
convenient.

Sorry to argue the bogosity, but this is an easy fix.  If anyone is
using solo \r's in dos, they shouldn't be using text-mode.


Previous Comments:
------------------------------------------------------------------------

[2003-11-27 07:41:44] [EMAIL PROTECTED]

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.

------------------------------------------------------------------------

[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

Reply via email to