From:             figaroap at wp dot pl
Operating system: Win XP SP2
PHP version:      6CVS-2007-07-26 (snap)
PHP Bug Type:     Filesystem function related
Bug description:  fgetcsv doesn't handle ""\n correctly in multiline csv record

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 bug report at http://bugs.php.net/?id=42110&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42110&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42110&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42110&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42110&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42110&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42110&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42110&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42110&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42110&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42110&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42110&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42110&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42110&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42110&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42110&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42110&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42110&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42110&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42110&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42110&r=mysqlcfg

Reply via email to