php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #67566 escape parameter in fgetcsv() is sometimes ignored
Submitted: 2014-07-04 08:10 UTC Modified: 2018-02-15 17:04 UTC
Votes:10
Avg. Score:4.8 ± 0.4
Reproduced:10 of 10 (100.0%)
Same Version:9 (90.0%)
Same OS:5 (50.0%)
From: sebastian dot schmidt at meap dot de Assigned: cmb (profile)
Status: Closed Package: Filesystem function related
PHP Version: Irrelevant OS: Debian 6.0.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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sebastian dot schmidt at meap dot de
New email:
PHP Version: OS:

 

 [2014-07-04 08:10 UTC] sebastian dot schmidt at meap dot de
Description:
------------
It seem that the 5th parameter $escape in fgetcsv() function is completly ignored when executing the function. I tested the script on 3 different minor php version (5.3.5, 5.4.11 ans 5.5.7)  all with the same result.

If you try to set the escape character to any other character than " (double-quote) php totally ignores the parameter and still uses the double-quote.

Also this behavior show that the default escape character, which should be the backslash as outlined in the documentation, is the double-quote.

Test script:
---------------
<?php 

$fileContents = <<<EOD
"quote \"testing\"",""
"quote ""testing""",""
"quote \,testing\,",""
EOD;

$handle = fopen('php://memory', 'w');
fwrite($handle, $fileContents);
fseek($handle, 0);

while(!feof($handle))
{
    $test = fgetcsv($handle, 0, ',', '"', '\\');
    print_r($test);
}
?>

Expected result:
----------------
Array
(
    [0] => quote "testing"
    [1] => 
)
Array
(
    [0] => quote ""testing""
    [1] => 
)
Array
(
    [0] => quote \,testing\,
    [1] => 
)

Actual result:
--------------
Array
(
    [0] => quote \"testing\"
    [1] => 
)
Array
(
    [0] => quote "testing"
    [1] => 
)
Array
(
    [0] => quote \,testing\,
    [1] => 
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-26 13:20 UTC] cmb@php.net
-Summary: escape parameter in fgetcsv() is always ignored +Summary: escape parameter in fgetcsv() is sometimes ignored -Status: Open +Status: Verified
 [2016-08-26 13:20 UTC] cmb@php.net
Confirmed: <https://3v4l.org/ZRbQa>. Note that the $escape
parameter is not always ignored, though, see bug #70491.
 [2018-02-15 14:43 UTC] cmb@php.net
-Status: Verified +Status: Assigned -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2018-02-15 14:43 UTC] cmb@php.net
Well, actually the escape parameter is not ignored for the given
test script.  For the first line it is important; if the quotes in
the first field were unescaped, it would result in garbage (see
<https://3v4l.org/sZbis>).

I'm changing to documentation problem, since obviously the
behavior needs to be clearly documented.
 [2018-02-15 17:04 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=344268
Log: Fix bug #67566: escape parameter in fgetcsv() is sometimes ignored

We clarify the actual meaning of $escape.
 [2018-02-15 17:04 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2018-02-15 17:04 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Tue Oct 23 10:01:27 2018 UTC