php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27082 double quotes in CSV files are not handled properly
Submitted: 2004-01-29 06:28 UTC Modified: 2004-01-29 10:21 UTC
From: christian at wenz dot org Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.3.5RC1 OS: Windows XP
Private report: No CVE-ID: None
 [2004-01-29 06:28 UTC] 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"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-29 09:20 UTC] 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 10:21 UTC] christian at wenz dot org
great, thanks!  -Christian
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 00:01:30 2024 UTC