#39538 [NEW]: fgetcsv can't handle starting newlines and trailing odd number of backslashes
| From: | mike at opendns dot com | Date: | Thu, 16 Nov 2006 20:48:29 +0000 |
| Subject: | #39538 [NEW]: fgetcsv can't handle starting newlines and trailing odd number of backslashes | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-105122@lists.php.net to get a copy of this message | ||
From: mike at opendns dot com
Operating system: Linux, debian sarge
PHP version: 5.2.0
PHP Bug Type: *Directory/Filesystem functions
Bug description: fgetcsv can't handle starting newlines and trailing odd number of backslashes
Description:
------------
Two issues when reading in data from a CSV with fgetcsv():
If an element in a CSV file begins with a newline, fgetcsv() will think
there's two newlines there.
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.
Reproduce code:
---------------
mikef@dev9:~$ cat -A /tmp/csv.tmp
"$
two seperate issues: string begins with a newline, ends with odd number of
backslashes \\\","and isnt the last element"$
mikef@dev9:~$ cat test_cvs.php
<?php
$tmp_file = '/tmp/csv.tmp';
$h = fopen($tmp_file, 'r');
$data_read_in = fgetcsv($h);
fclose($h);
var_dump($data_read_in);
?>
Expected result:
----------------
mikef@dev9:~$ php test_cvs.php
array(2) {
[0]=>
string(92) "
two seperate issues: string begins with a newline, ends with odd number of
backslasshes \\\"
[1]=>
string(25) "and isnt the last element"
}
Actual result:
--------------
mikef@dev9:~$ php test_cvs.php
array(1) {
[0]=>
string(121) "
two seperate issues: string begins with a newline, ends with odd number of
backslashes \\\",and isnt the last element""
}
--
Edit bug report at http://bugs.php.net/?id=39538&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39538&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39538&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39538&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39538&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=39538&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39538&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39538&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39538&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39538&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39538&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=39538&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=39538&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39538&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39538&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39538&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39538&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39538&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39538&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39538&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39538&r=mysqlcfg