ID:               27573
 Updated by:       [EMAIL PROTECTED]
 Reported By:      ib at wupperonline dot de
-Status:           Open
+Status:           Bogus
 Bug Type:         Filesystem function related
 Operating System: Windows 2000
 PHP Version:      4.3.4
 New Comment:

>From http://www.php.net/fopen



Windows offers a text-mode translation flag ('t') which will
transparently translate \n to \r\n when working with the file. In
contrast, you can also use 'b' to force binary mode, which will not
translate your data. To use these flags, specify either 'b' or 't' as
the last character of the mode parameter. 



As of PHP 4.3.2, the default mode is set to binary for all platforms
that distinguish between binary and text mode. If you are having
problems with your scripts after upgrading, try using the 't' flag as a
workaround until you have made your script more portable as mentioned
above. 






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

[2004-03-11 12:31:46] ib at wupperonline dot de

Description:
------------
Using mode "r" to fopen files under Windows doesn't open them in text
mode (as it should), but in binary mode, thus working exactly like
"rb". Reading these files, you'll get "\r\n" instead of "\n" for new
line character.



Surprisingly, fopen accepts mode "rt" which isn't documented but works
as "r" should. It opens in text mode and returns "\n" instead of
"\r\n".

Reproduce code:
---------------
Create a file named dat.txt containing 4 bytes: "1", CR, LF, "2", LF.



$f = fopen("dat.txt", "r");



$d = fread($f, 1);

echo ord($d) . " ";

$d = fread($f, 1);

echo ord($d) . " ";

$d = fread($f, 1);

echo ord($d) . " ";

$d = fread($f, 1);

echo ord($d) . " ";



fclose($f);

Expected result:
----------------
49 10 50 10

Actual result:
--------------
49 13 10 50


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


-- 
Edit this bug report at http://bugs.php.net/?id=27573&edit=1

Reply via email to