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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: christian at wenz dot org
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2023 The PHP Group
All rights reserved.
Last updated: Wed Feb 01 20:04:13 2023 UTC