|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-02-24 00:02 UTC] ceefour at gauldong dot net
Description:
------------
Using 'wt' (write-text), any \n should be translated to \r\n (0D 0A).
However in my system, PHP 5.0.3 in Windows XP SP1, this mode translates \n to \r only (0D), which results in MAC-style line endings.
I had to use 'wb' (write-binary) and put \r\n manually to get desired results.
Reproduce code:
---------------
$fp = fopen('anyfile.txt', 'wt');
fwrite($fp, "Hello\n");
fclose($fp);
Expected result:
----------------
anyfile.txt contains "Hello" + 0D 0A (\r \n)
Actual result:
--------------
anyfile.txt contains "Hello" + 0D (\r only)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Jan 07 14:00:01 2026 UTC |
BTW, for *PORTABILITY* I choose 't' (text mode), so it works both for UNIXes and Windows, even MACs. I don't want to do this: fopen(...., 'wb') if (strpos('win', strtolower(PHP_OS)) !== false) { $line_ending = "\r\n"; } else { $line_ending = "\n"; } which is NOT PORTABLE AT ALL. Why do you suggest 'b' mode will be more portable? The documentation is weird, IMHO.