|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76940 fgetcsv not correctly parsing fputcsv output
Submitted: 2018-09-27 05:44 UTC Modified: 2018-09-27 08:56 UTC
From: simon dot welsh at themarkagency dot com dot au Assigned: cmb (profile)
Status: Duplicate Package: *Directory/Filesystem functions
PHP Version: 7.3.0RC1 OS: macOS + Linux
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: simon dot welsh at themarkagency dot com dot au
New email:
PHP Version: OS:


 [2018-09-27 05:44 UTC] simon dot welsh at themarkagency dot com dot au
When a value passed to `fputcsv` ends with the escape character, `fgetcsv` (and `str_getcsv`) do not correctly parse it.

I'm not sure if this is an issue with `fputcsv` not escaping the escape character or `fgetcsv` not handling things properly.

Test script:

$input = array(1, 3, '3\\', 5, 3);
$f = fopen('php://temp,', 'w+');
fputcsv($f, $input);
$output = stream_get_contents($f);

var_dump($input, $output, str_getcsv($output), fgetcsv($f));

Expected result:
I expect `$input` and the results from `str_getcsv` and `fgetcsv` to be the same

Actual result:
The final three fields, including separators, are parsed as a single field.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-27 08:56 UTC]
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2018-09-27 08:56 UTC]
Basically a duplicate of bug #74713.

As workaround you may be able to use "\0" as $escape parameter of
fgetcsv() and fputcsv().
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Sep 20 23:03:37 2021 UTC