|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
10 + 26 = ?
Subscribe to this entry?

 [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: Fri Oct 22 04:03:33 2021 UTC