ID: 27573 Updated by: [EMAIL PROTECTED] Reported By: ib at wupperonline dot de -Status: Bogus +Status: Open -Bug Type: Filesystem function related +Bug Type: Documentation problem Operating System: Windows 2000 PHP Version: 4.3.4 New Comment:
That is correct; fopen was changed to work in binary mode by default in order to be more portable. I thought this was mentioned in the NEWS file, but apparently not. The change was made in PHP 4.3.2. The undocumented 't' mode has been a feature of the MSVCRT since forever. This stuff needs documenting fairly prominently. Previous Comments: ------------------------------------------------------------------------ [2004-03-11 13:27:57] [EMAIL PROTECTED] >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. ------------------------------------------------------------------------ [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
