php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67566 escape parameter in fgetcsv() is sometimes ignored
Submitted: 2014-07-04 08:10 UTC Modified: 2016-08-26 13:20 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:
Status: Verified 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.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC