Bug #44034 [Opn->Wfx]: FILE_IGNORE_NEW_LINES in FILE does not work as expected when lines end in \r\n
| From: | felipe@php.net | Date: | Sun, 20 Jun 2010 22:29:24 +0000 |
| Subject: | Bug #44034 [Opn->Wfx]: FILE_IGNORE_NEW_LINES in FILE does not work as expected when lines end in \r\n | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-151691@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=44034&edit=1
ID: 44034
Updated by: felipe@php.net
Reported by: php at commerco dot net
Summary: FILE_IGNORE_NEW_LINES in FILE does not work as
expected when lines end in \r\n
-Status: Open
+Status: Wont fix
Type: Bug
Package: Filesystem function related
Operating System: Win2K
PHP Version: 6CVS-2008-02-04 (snap)
New Comment:
Old trunk related.
Previous Comments:
------------------------------------------------------------------------
[2008-02-10 06:57:17] php at commerco dot net
Thank you for your post. Unfortunately, the current build version
(php6.0-win32-200802041530) did not cure the issue.
------------------------------------------------------------------------
[2008-02-04 08:40:49] php at commerco dot net
Description:
------------
Using FILE, when the parameter FILE_IGNORE_NEW_LINES is used, if the
file uses a line termination of \n the operation works as expected.
If the file uses a line termination of \r\n (MS Windows), the \r is not
removed.
One might argue that the NEW_LINES is \n alone, and of course FILE works
fine when the file has a \n terminator, however, \r\n is a common line
record (line) terminator on a windows system. If memory serves, this
kind of issue has been addressed in some other PHP functions, so it
would be great if you would consider addressing this one too.
The problem really becomes apparent if you take two arrays derived from
FILE functions and combine them via an array_combine.
Reproduce code:
---------------
/* create 2 files in notepad.
$somefile1 data:
foo
bar
etc
$somefile2 data:
123
456
789
*/
$a1 = file($somefile1, FILE_IGNORE_NEW_LINES+FILE_TEXT);
$a2 = file($somefile2, FILE_IGNORE_NEW_LINES+FILE_TEXT);
$a3 = array_combine($a1, $a2);
print_r($a3);
Expected result:
----------------
$a3 is an array with three entries with both key and data each entry
having a length of 3 bytes.
Array
(
[foo] => 123
[bar] => 456
[etc] => 789
)
(which is what happens when a file contains \n terminated lines).
Actual result:
--------------
$a3 is an array with three entries with both key and data each entry
having a length of 4 bytes.
Array
(
[foo
] => 123
[bar
] => 456
[etc
] => 789
)
(which is what happens when a file contains \r\n terminated lines).
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=44034&edit=1