php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39538 fgetcsv can't handle starting newlines and trailing odd number of backslashes
Submitted: 2006-11-16 20:48 UTC Modified: 2006-11-22 13:07 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: mike at opendns dot com Assigned: dsp (profile)
Status: Closed Package: *Directory/Filesystem functions
PHP Version: 5.2.0 OS: Linux, debian sarge
Private report: No CVE-ID: None
 [2006-11-16 20:48 UTC] mike at opendns dot com
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""
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-22 13:07 UTC] pajoye@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fixed using a patch from David Soria Parra.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 11:01:29 2024 UTC