|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22382 fgetcsv does not allow escaped quotes
Submitted: 2003-02-22 19:45 UTC Modified: 2003-02-23 21:17 UTC
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: Stevenv at operamail dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.3.2-dev OS: FreeBSD 4.7
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: Stevenv at operamail dot com
New email:
PHP Version: OS:


 [2003-02-22 19:45 UTC] Stevenv at operamail dot com
As the summary says, fgetcsv does not allow escaped quotes. When csv fields come from user input, it is often the case that addslashes() is run on them then enclosed in quotes. However, fgetcsv() removes anything after the escaped quote.


/* make a csv file */
$fp = fopen('csv_file', 'w+');
$fields = array();

$fields[0] = '"' . addslashes('This is "Field One"') . '"';
$fields[1] = 'field two';
$fields[2] = 'field three';
fwrite($fp, implode(',', $fields));

/* start all over */
fseek($fp, 0);
var_dump(fgetcsv($fp, 4096));

array(3) {
  string(9) "This is \"
  string(9) "field two"
  string(11) "field three"

The behavior I expected would have been for the first field to read:
"This is \"Field One\""

Much like the functionality described on < specification>.



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-23 21:17 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 08:01:26 2019 UTC