php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71226 fgetcsv does not split correctly
Submitted: 2015-12-27 12:01 UTC Modified: 2015-12-27 12:27 UTC
From: kingma at bluewin dot ch Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.6.16 OS: Windows 10
Private report: No CVE-ID: None
 [2015-12-27 12:01 UTC] kingma at bluewin dot ch
Description:
------------
The lines are not split correctly at the delimiters, also enclosure characters end up in the resulting array.

Test script:
---------------
$fh = fopen('test_import.csv', "r");
$header = fgetcsv($fh,$delimiter=';',$enclosure='"', $length=0); //skip headers
print_r($header);echo "\n";
$line = fgetcsv($fh,$delimiter=';',$enclosure='"');
print_r($line);echo "\n";

test_import.csv contains
A;B;C;D;E;F
A;"B";C;"D";E;F


Expected result:
----------------
Array ( [0] => A; [1] => B [2] => C [3] => D [4] => E [5] => F )
Array ( [0] => A; [1] => B [2] => C [3] => D [4] => E [5] => F )

Actual result:
--------------
Array ( [0] => A;B;C;D;E;F )
Array ( [0] => A; [1] => B [2] => ;C; [3] => D [4] => ;E;F )

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-27 12:27 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-12-27 12:27 UTC] requinix@php.net
> fgetcsv($fh,$delimiter=';',$enclosure='"', $length=0);
Named arguments are not a thing. Call the function correctly.

http://php.net/manual/en/function.fgetcsv.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 19:01:28 2024 UTC