Bug #44034 [Com]: FILE_IGNORE_NEW_LINES in FILE does not work as expected when lines end in \r\n
Edit report at https://bugs.php.net/bug.php?id=44034&edit=1
ID: 44034
Comment by: php at yopmail dot com
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: Wont fix
Type: Bug
Package: Filesystem function related
Operating System: Win2K
PHP Version: 6CVS-2008-02-04 (snap)
Block user comment: N
Private report: N
New Comment:
Fixed in PHP 5.2.10 / 5.3.0 and higher <https://3v4l.org/eA9gM>
Previous Comments:
------------------------------------------------------------------------
[2010-06-21 00:29:24] felipe@php.net
Old trunk related.
------------------------------------------------------------------------
[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 https://bugs.php.net/bug.php?id=44034&edit=1
Thread (5 messages)