#41609 [Opn]: file_put_contents() injects \r
| From: | zoe at uk dot ibm dot com | Date: | Wed, 06 Jun 2007 10:48:09 +0000 |
| Subject: | #41609 [Opn]: file_put_contents() injects \r | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-113461@lists.php.net to get a copy of this message | ||
ID: 41609
User updated by: zoe at uk dot ibm dot com
Reported By: zoe at uk dot ibm dot com
Status: Open
Bug Type: Filesystem function related
Operating System: Windows XP
PHP Version: 6CVS-2007-06-06 (snap)
New Comment:
Hi Johannes
No, it doesn't:
E:\zoe\TESTS\slashr>e:\zoe\buildsystem\php6exe\php.exe -d
unicode.semantics=0 johannes.php
string(7) "foo
bar"
E:\zoe\TESTS\slashr>e:\zoe\buildsystem\php6exe\php.exe -d
unicode.semantics=1 johannes.php
string(7) "foo
bar"
Previous Comments:
------------------------------------------------------------------------
[2007-06-06 10:26:31] johannes@php.net
I'd assume this is some ICU feature when converting a text with
newlines from UTF-8 to UTF-16 and then back to UTF-8.
Does something like
<?php
$a = "foo\nbar";
var_dump((binary)$a);
?>
also show the \r?
------------------------------------------------------------------------
[2007-06-06 09:35:57] tony2001@php.net
No, thanks. This should be enough for somebody who knows how to debug
it on Windows.
Unfortunately, I don't.
------------------------------------------------------------------------
[2007-06-06 08:56:30] zoe at uk dot ibm dot com
Hi - sorry - I should have mentioned that the behaviour is not
reproducible on Linux. It's Windows specific. Would you like the copies
of the data.tmp files that are created in each case? - if so I'll attach
them to this.
------------------------------------------------------------------------
[2007-06-06 08:38:47] tony2001@php.net
Could you plz try the same on Linux?
I can't replicate it there.
------------------------------------------------------------------------
[2007-06-06 08:08:15] zoe at uk dot ibm dot com
Description:
------------
A file created on Windows using file_put_contents in PHP6 has different
contents if unicode.semantics=1 is used.
The files (data.tmp) created by the test case below have different
contents, from "od -x" it looks to me as though an additional \r is
inserted in the file before the \n.
Reproduce code:
---------------
<?php
$file_path = dirname(__FILE__);
$buffer = "text\nline of text\n";
file_put_contents( $file_path."/data.tmp", (binary)$buffer);
$fp = fopen($file_path."/data.tmp", "r");
var_dump( file_get_contents($file_path."/data.tmp") );
fclose($fp);
$fp = fopen($file_path."/data.tmp", "r");
var_dump( fgets($fp) );
fclose($fp);
$fp = fopen($file_path."/data.tmp", "rb");
var_dump( fgets($fp) );
fclose($fp);
$fp = fopen($file_path."/data.tmp", "rt");
var_dump( fgets($fp) );
fclose($fp);
?>
Expected result:
----------------
string(18) "text
line of text
"
string(5) "text
"
string(5) "text
"
string(5) "text
"
Actual result:
--------------
string(20) "text
line of text
"
string(6) "text
"
string(6) "text
"
unicode(5) "text
"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41609&edit=1