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

2005-02-25 Thread sniper
 ID:   32090
 Updated by:   [EMAIL PROTECTED]
 Reported By:  ceefour at gauldong dot net
-Status:   Open
+Status:   Feedback
 Bug Type: Filesystem function related
 Operating System: Windows XP SP1
 PHP Version:  5.0.3
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

And yes, mbstring might be the one causing trouble. Always try
disabling everything possible.



Previous Comments:


[2005-02-24 03:23:22] ceefour at gauldong dot net

Hi Mr. Furlong! Thanks for the feedback.

The test case is complete. And I'm viewing it using a hex editor
(doesn't matter which). The Hello\n will output exactly 6 bytes, the
Hello and the 0D (\r). It's a MAC document, as detected by a good text
editor. If you try to output more lines, i.e., Hello\nWorld, the text
will get concatenated if you try to use Notepad. Viewing it in WordPad
or any other good text editor works fine.

FYI: text mode is an evil invention that usually leads to trouble.

I agree with you. But it doesn't solve the problem. As stated in my
previous problem, I can write code which use explicit line endings, but
that will require me to write if statements for who-knows-how-many
platforms I will need to support. It's easier that way.

Do you know setlocale() ? Yeah, try EXPLICITLY specifying your
locale-specific formats without using strftime()-s formats and/or
setlocale(). Things like this IMHO should be handled at lower levels of
abstraction. And even if not, the lower level library should give the
programmer a choice, i.e.: we recommend you NOT to use it but if you
use it we guarantee it will work correctly. In this case 'wt' doesn't
work correctly.

BTW I can even e-mail you the exact script, the exact generated file,
and even my entire PHP installation if you want to. ;-)

BTW in case you're wondering I use the mbstring extension with UTF-8
internal encoding specified in php.ini... but it shouldn't matter,
should it?



[2005-02-24 01:52:04] [EMAIL PROTECTED]

Please provide a complete test case; most of these so called bug
reports are due to the person viewing the data using the wrong tools.

FYI: text mode is an evil invention that usually leads to trouble. 
It is generally better for the programmer to be explicit with their
line endings, as it leads to a lower WTF? factor.



[2005-02-24 00:10:09] ceefour at gauldong dot net

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.



[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=32090edit=1


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

2005-02-23 Thread wez
 ID:   32090
 Updated by:   [EMAIL PROTECTED]
 Reported By:  ceefour at gauldong dot net
-Status:   Open
+Status:   Feedback
 Bug Type: Filesystem function related
 Operating System: Windows XP SP1
 PHP Version:  5.0.3
 New Comment:

Please provide a complete test case; most of these so called bug
reports are due to the person viewing the data using the wrong tools.

FYI: text mode is an evil invention that usually leads to trouble. 
It is generally better for the programmer to be explicit with their
line endings, as it leads to a lower WTF? factor.


Previous Comments:


[2005-02-24 00:10:09] ceefour at gauldong dot net

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.



[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=32090edit=1