#27082 [NEW]: double quotes in CSV files are not handled properly
| From: | christian at wenz dot org | Date: | Thu, 29 Jan 2004 11:28:50 +0000 |
| Subject: | #27082 [NEW]: double quotes in CSV files are not handled properly | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-54114@lists.php.net to get a copy of this message | ||
From: christian at wenz dot org
Operating system: Windows XP
PHP version: 4.3.5RC1
PHP Bug Type: Filesystem function related
Bug description: double quotes in CSV files are not handled properly
Description:
------------
According to the CSV spec at http://rath.ca/Misc/Perl_CSV/CSV-2.0.html ,
quotes within CSV files can be escaped by "doubling" the quotes. So if you
have a CSV file with two values:
I think this "IS" a bug
another value
then the CSV file would look like this:
"I think this ""IS"" a bug",another value
However, when reading such a CSV file using fgetcsv, the doubled quotes
are not transformed into single quotes as expected.
Reproduce code:
---------------
<?php
$fp = fopen("csv_file", "w+");
$fields = array();
$fields[0] = '"I think this ""IS"" a bug"';
$fields[1] = "another field";
fwrite($fp, implode(",", $fields));
fseek($fp, 0);
var_dump(fgetcsv($fp, 4096));
?>
Expected result:
----------------
array(2) {
[0]=>
string(23) "I think this "IS" a bug"
[1]=>
string(13) "another field"
}
Actual result:
--------------
array(2) {
[0]=>
string(25) "I think this ""IS"" a bug"
[1]=>
string(13) "another field"
}
--
Edit bug report at http://bugs.php.net/?id=27082&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27082&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27082&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=27082&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=27082&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=27082&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=27082&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=27082&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=27082&r=support
Expected behavior: http://bugs.php.net/fix.php?id=27082&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=27082&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=27082&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=27082&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27082&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=27082&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=27082&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=27082&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27082&r=float