|  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.
Block user comment
Status: Assign to:
Bug Type:
From: christian at wenz dot org
New email:
PHP Version: OS:


 [2004-01-29 06:28 UTC] christian at wenz dot org
According to the CSV spec at , 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:
$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) {
  string(23) "I think this "IS" a bug"
  string(13) "another field"

Actual result:
array(2) {
  string(25) "I think this ""IS"" a bug"
  string(13) "another field"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-29 09:20 UTC]
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
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