#22382 [Fbk->Ver]: fgetcsv does not allow escaped quotes
ID: 22382
Updated by: sniper@php.net
Reported By: Stevenv at operamail dot com
-Status: Feedback
+Status: Verified
Bug Type: Filesystem function related
Operating System: FreeBSD 4.7
-PHP Version: 4.3.0
+PHP Version: 4.3.2-dev
New Comment:
I take that back, it isn't fixed in that snapshot,
so don't bother testing.
Verified within 4.3.2-dev.
Previous Comments:
------------------------------------------------------------------------
[2003-02-22 21:18:38] sniper@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php4-STABLE-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php4-win32-STABLE-latest.zip
AFAIK, this is already fixed.
------------------------------------------------------------------------
[2003-02-22 19:45:00] Stevenv at operamail dot com
As the summary says, fgetcsv does not allow escaped quotes. When csv
fields come from user input, it is often the case that addslashes() is
run on them then enclosed in quotes. However, fgetcsv() removes
anything after the escaped quote.
Code:
<?php
/* make a csv file */
$fp = fopen('csv_file', 'w+');
$fields = array();
$fields[0] = '"' . addslashes('This is "Field One"') .
'"';
$fields[1] = 'field two';
$fields[2] = 'field three';
fwrite($fp, implode(',', $fields));
/* start all over */
fseek($fp, 0);
var_dump(fgetcsv($fp, 4096));
?>
Outputs:
array(3) {
[0]=>
string(9) "This is \"
[1]=>
string(9) "field two"
[2]=>
string(11) "field three"
}
The behavior I expected would have been for the first field to read:
"This is \"Field One\""
Much like the functionality described on
<http://rath.ca/Misc/Perl_CSV/CSV-2.0.html#csv
specification>.
Thanks
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=22382&edit=1
Thread (7 messages)