Bug->Doc #67566 [Ver->Asn]: escape parameter in fgetcsv() is sometimes ignored

From: Date: Thu, 15 Feb 2018 14:44:01 +0000
Subject: Bug->Doc #67566 [Ver->Asn]: escape parameter in fgetcsv() is sometimes ignored
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-15439@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67566&edit=1 ID: 67566 Updated by: cmb@php.net Reported by: sebastian dot schmidt at meap dot de Summary: escape parameter in fgetcsv() is sometimes ignored -Status: Verified +Status: Assigned -Type: Bug +Type: Documentation Problem Package: Filesystem function related Operating System: Debian 6.0.7 PHP Version: Irrelevant -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2016-08-26 14:02:24] cmb@php.net Related To: Bug #51496 ------------------------------------------------------------------------ [2016-08-26 13:36:36] cmb@php.net Related To: Bug #66727 ------------------------------------------------------------------------ [2016-08-26 13:20:52] cmb@php.net Confirmed: <https://3v4l.org/ZRbQa>. Note that the $escape parameter is not always ignored, though, see bug #70491. ------------------------------------------------------------------------ [2014-07-04 08:10:35] 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] => ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67566&edit=1

« previous php.doc.bugs (#15439) next »