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
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:
6 + 40 = ?
Subscribe to this entry?

 
 [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.
 [2020-02-07 06:05 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=9421e06e34c689a3511a3fe889db295540bcf3a5
Log: Fix bug #67566: escape parameter in fgetcsv() is sometimes ignored
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 09:01:29 2024 UTC