From: sthomas at townnews dot com
Operating system: Linux
PHP version: 4CVS-2004-02-24 (stable)
PHP Bug Type: Filesystem function related
Bug description: Fgetcsv not quite handling enclosures properly
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 bug report at http://bugs.php.net/?id=27378&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27378&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27378&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=27378&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=27378&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=27378&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=27378&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=27378&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=27378&r=support
Expected behavior: http://bugs.php.net/fix.php?id=27378&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=27378&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=27378&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=27378&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27378&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=27378&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=27378&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=27378&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27378&r=float