#32090 [Opn]: fopen(..., 'wt') - fwrite($fp, ...) translates \n to \r

From: Date: Wed, 23 Feb 2005 23:10:10 +0000
Subject: #32090 [Opn]: fopen(..., 'wt') - fwrite($fp, ...) translates \n to \r
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-74491@lists.php.net to get a copy of this message
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

« previous php.bugs (#74491) next »