php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42110 fgetcsv doesn't handle ""\n correctly in multiline csv record
Submitted: 2007-07-26 12:11 UTC Modified: 2010-06-20 20:08 UTC
Votes:10
Avg. Score:4.4 ± 0.8
Reproduced:8 of 8 (100.0%)
Same Version:1 (12.5%)
Same OS:1 (12.5%)
From: figaroap at wp dot pl Assigned:
Status: Wont fix Package: Filesystem function related
PHP Version: 6CVS-2007-07-26 (snap) OS: Win XP SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
14 + 48 = ?
Subscribe to this entry?

 
 [2007-07-26 12:11 UTC] 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
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-20 20:07 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2010-06-20 20:07 UTC] felipe@php.net
This just occurred in the old trunk version.
 [2010-06-20 20:08 UTC] felipe@php.net
-Status: Bogus +Status: Wont fix
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 16:01:29 2024 UTC