ID: 32090
User updated by: ceefour at gauldong dot net
Reported By: ceefour at gauldong dot net
Status: Open
Bug Type: Filesystem function related
Operating System: Windows XP SP1
PHP Version: 5.0.3
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2005-02-24 00:02:06] 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)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32090&edit=1