#46872 [Opn->Csd]: fgetcsv escape character is misleading
| From: | vrana@php.net | Date: | Fri, 20 Nov 2009 11:31:54 +0000 |
| Subject: | #46872 [Opn->Csd]: fgetcsv escape character is misleading | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-3277@lists.php.net to get a copy of this message | ||
ID: 46872
Updated by: vrana@php.net
Reported By: jordan dot raub at dataxltd dot com
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: *
PHP Version: Irrelevant
New Comment:
Escape parameter already documented but seems buggy in PHP 5.3.1.
Please report a bug for Filesystem functions.
Previous Comments:
------------------------------------------------------------------------
[2008-12-15 20:19:52] jordan dot raub at dataxltd dot com
tested w/ php5.3alpha3 and got this...
array(2) {
[0]=>
string(17) "quote \"testing\""
[1]=>
string(4) "test"
}
array(2) {
[0]=>
string(15) "quote "testing""
[1]=>
string(4) "test"
}
------------------------------------------------------------------------
[2008-12-15 19:08:55] jordan dot raub at dataxltd dot com
Description:
------------
the documentation is misleading for fgetcsv.
\ is not the escape char for 5.2.8
double double quotes ("") will escape a double quote w/in a field.
I think the functionality is correct as is, so the docs should just be
changed.
see http://en.wikipedia.org/wiki/Comma-separated_values
Reproduce code:
---------------
<?php
$fileContents = <<<EOD
"quote \"testing\"",""
"quote ""testing""",""
EOD;
$handle = fopen('php://memory', 'w');
fwrite($handle, $fileContents);
fseek($handle, 0);
while(!feof($handle))
{
var_dump(fgetcsv($handle));
}
Expected result:
----------------
array(2) {
[0]=>
string(15) "quote "testing""
[1]=>
string(4) "test"
}
array(2) {
[0]=>
string(17) "quote ""testing"""
[1]=>
string(4) "test"
}
Actual result:
--------------
array(2) {
[0]=>
string(17) "quote \"testing\""
[1]=>
string(4) "test"
}
array(2) {
[0]=>
string(15) "quote "testing""
[1]=>
string(4) "test"
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46872&edit=1