From: php at commerco dot net
Operating system: MS Win2K
PHP version: 6CVS-2008-02-04 (snap)
PHP Bug Type: Filesystem function related
Bug description: FILE_IGNORE_NEW_LINES in FILE does not work as expected when
lines end in \r\n
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 bug report at http://bugs.php.net/?id=44034&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=44034&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=44034&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=44034&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=44034&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44034&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=44034&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44034&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44034&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44034&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44034&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44034&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=44034&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=44034&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44034&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=44034&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=44034&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44034&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44034&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44034&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44034&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44034&r=mysqlcfg