#40501 [Com]: fgetcsv can't handle trailing odd number of backslashes
| From: | frapa02 at hotmail dot com | Date: | Wed, 18 Apr 2007 09:00:16 +0000 |
| Subject: | #40501 [Com]: fgetcsv can't handle trailing odd number of backslashes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-111635@lists.php.net to get a copy of this message | ||
ID: 40501
Comment by: frapa02 at hotmail dot com
Reported By: mike at opendns dot com
Status: Open
Bug Type: Filesystem function related
Operating System: Linux, debian sarge
PHP Version: 5.2.1
New Comment:
I am experiencing this issue which is preventing me from processing
standard CSV file fields which have a backslash as the last character
before the double quote enclosure. e.g.
"field 1","field 2","field 3\",field 4"
This will result in fgetcsv only returning 3 fields instead of 4.
Perhaps the best way to fix this is to remove the test for
'escape_char' in the 'php_fgetcsv' function. If backward compatibility
is an issue, an additional parm to fgetcsv could be added to enable the
use of the escape character. It's default should be to use no escape
character.
Previous Comments:
------------------------------------------------------------------------
[2007-02-15 20:11:54] mike at opendns dot com
Description:
------------
If an element in a CSV file ends with an odd number of trailing
backslashes, it'll miss the enclosure character.
This isn't a documentation problem -
http://www.rfc-editor.org/rfc/rfc4180.txt
Backslashes are not escape characters in CSV.
This was part of bug #39538. The other half of that bug was correctly
fixed. This is still broken.
Reproduce code:
---------------
mikef@dev5:/tmp# cat -A csv.tmp
"this element contains the delimiter, and ends with an odd number of
backslashes (ex: 1)\",and it isn't the last element$
mikef@dev5:/tmp# cat test_csv.php
<?php
$file = '/tmp/csv.tmp';
$h = fopen($file, 'r');
$data = fgetcsv($h);
fclose($h);
var_dump($data);
?>
Expected result:
----------------
mikef@dev5:/tmp# php test_csv.php
array(2) {
[0]=>
string(88) "this element contains the delimiter, and ends with an odd
number of backslashes (ex: 1)\"
[1]=>
string(29) "and it isn't the last element"
}
Actual result:
--------------
mikef@dev5:/tmp# php test_csv.php
array(1) {
[0]=>
string(120) "this element contains the delimiter, and ends with an
odd number of backslashes (ex: 1)\",and it isn't the last element"
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40501&edit=1