php.net |  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:
MUST BE VALID
Solve the problem:
34 + 27 = ?
Subscribe to this entry?

 
 [2018-09-27 05:44 UTC] simon dot welsh at themarkagency dot com dot au
Description:
------------
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:
---------------
<?php

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

rewind($f);
var_dump($input, $output, str_getcsv($output), fgetcsv($f));
fclose($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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-27 08:56 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2018-09-27 08:56 UTC] cmb@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 07:01:27 2024 UTC