Bug #42110 [Bgs->Wfx]: fgetcsv doesn't handle ""\n correctly in multiline csv record
| From: | felipe@php.net | Date: | Sun, 20 Jun 2010 18:08:16 +0000 |
| Subject: | Bug #42110 [Bgs->Wfx]: fgetcsv doesn't handle ""\n correctly in multiline csv record | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-151667@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=42110&edit=1
ID: 42110
Updated by: felipe@php.net
Reported by: figaroap at wp dot pl
Summary: fgetcsv doesn't handle ""\n correctly in multiline csv
record
-Status: Bogus
+Status: Wont fix
Type: Bug
Package: Filesystem function related
Operating System: Win XP SP2
PHP Version: 6CVS-2007-07-26 (snap)
Previous Comments:
------------------------------------------------------------------------
[2010-06-20 20:07:55] felipe@php.net
This just occurred in the old trunk version.
------------------------------------------------------------------------
[2007-07-26 12:11:39] figaroap at wp dot pl
Description:
------------
The fgetcsv has some really strange behaviour under PHP6. When parsing a
multi line record, if it begins with """ (one quote for enclosure and
two quotes for an escaped quote within text) and just before the line
break there is "", it will skip the beginning quote, add an empty array
field, then output the 2nd line of the multi line csv record and you get
some random empty fields in following records. The example attached
clearly shows the problem described above. The code works as expected
under PHP5.
Reproduce code:
---------------
test.php
<?php
$file = fopen("test.csv", 'rb');
while (($row = fgetcsv($file, 6000, ';', '"')) !== FALSE) {
print_r($row);
}
?>
test.csv
"A";"""Some long text""
some more";"1"
"B";"""Hmm""";"2"
Expected result:
----------------
Array
(
[0] => A
[1] => "Some long text"
some more
[2] => 1
)
Array
(
[0] => B
[1] => "Hmm"
[2] => 2
)
Actual result:
--------------
Array
(
[0] => A
[1] => Some long text"
[2] =>
[3] => some more"
[4] => 1
[5] =>
)
Array
(
[0] => B
[1] => "Hmm"
[2] => 2
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=42110&edit=1