#27082 [Csd]: double quotes in CSV files are not handled properly
| From: | christian at wenz dot org | Date: | Thu, 29 Jan 2004 15:21:25 +0000 |
| Subject: | #27082 [Csd]: double quotes in CSV files are not handled properly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-54129@lists.php.net to get a copy of this message | ||
ID: 27082
User updated by: christian at wenz dot org
Reported By: christian at wenz dot org
Status: Closed
Bug Type: Filesystem function related
Operating System: Windows XP
PHP Version: 4.3.5RC1
New Comment:
great, thanks! -Christian
Previous Comments:
------------------------------------------------------------------------
[2004-01-29 09:20:18] iliaa@php.net
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
------------------------------------------------------------------------
[2004-01-29 06:28:50] christian at wenz dot org
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 this bug report at http://bugs.php.net/?id=27082&edit=1