#27378 [Opn->Bgs]: Fgetcsv not quite handling enclosures properly

From: Date: Tue, 24 Feb 2004 21:51:34 +0000
Subject: #27378 [Opn->Bgs]: Fgetcsv not quite handling enclosures properly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-55488@lists.php.net to get a copy of this message
ID: 27378 Updated by: iliaa@php.net Reported By: sthomas at townnews dot com -Status: Open +Status: Bogus Bug Type: Filesystem function related Operating System: Linux PHP Version: 4CVS-2004-02-24 (stable) New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php This is how it is supposed to work, I've tried this in Open Office & MS Office (excel) and got the same data as the one generated by PHP. Previous Comments: ------------------------------------------------------------------------ [2004-02-24 10:36:16] sthomas at townnews dot com Description: ------------ Fgetcsv appears to have been rewritten from 4.3.4 which was a bit buggy. But there is still one unresolved issue with csv parsing I noticed in tests where the enclosure character is stripped from the text regardless of its enclosure status if it begins the string, but does not end the string. Reproduce code: --------------- Example file: blabla,"stuff with thing",yay foo,stuff with "thing",moo blarg,"stuff" with thing,goop Script: <?PHP $fp = fopen("/tmp/ctext.txt", "r"); while ($aLine = fgetcsv($fp, 8192, '|', '"')) { print_r($aLine); } fclose($fp); ?> Expected result: ---------------- Array ( [0] => blabla [1] => stuff with thing [2] => yay ) Array ( [0] => foo [1] => stuff with "thing" [2] => moo ) Array ( [0] => blarg [1] => "stuff" with thing [2] => goop ) Actual result: -------------- Note the missing quotes around "stuff" in the third array. I can only assume beginning the string with quotes makes PHP think the whole string is quoted, so it strips the first and second quotes it finds. Array ( [0] => blabla [1] => stuff with thing [2] => yay ) Array ( [0] => foo [1] => stuff with "thing" [2] => moo ) Array ( [0] => blarg [1] => stuff with thing [2] => goop ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=27378&edit=1

« previous php.bugs (#55488) next »