php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48313 fgetcsv() does not report empty row as documented
Submitted: 2009-05-17 20:16 UTC Modified: 2009-05-18 18:49 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: bitworks at web dot de Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5.2.9 OS: Windows XP SP3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
50 + 26 = ?
Subscribe to this entry?

 
 [2009-05-17 20:16 UTC] bitworks at web dot de
Description:
------------
reading data with fgetcsv() an empty row wil not be returned as one array element pointing to NULL, as it is described in documentation

the result for the record will be

array(1) {
  [0]=>
  string(0) ""
}

instead of

array(1) {
  [0]=>
  NULL
}




Expected result:
----------------
array(1) {
  [0]=>
  NULL
}

Actual result:
--------------
array(1) {
  [0]=>
  string(0) ""
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-17 20:34 UTC] bitworks at web dot de
<?php    ### bugreport_48313.php ###

    $fh = fopen('csv02.txt','r');
    
    if (!$fh) die('wrong filename');
    
    $_file = array();
    $_rec = array();

    while (false!==($_rec = fgetcsv($fh, 8192, ';','"')))
    {
        $_file[] = $_rec;
    }
   
    fclose($fh);

    echo "<pre>\r\n";
    var_dump($_file);
    echo "</pre>\r\n";

?> 

You will need a csv-file with some data and also an empty line in it.


nr;betreff;anzahl;beschreibung
"1";"Erste Zeile";"0";"Text"
"2";"Zeite Zeile";"0.11";"mehr Text"
"3";"Dritte Zeile";"";"kein Eintrag vorhanden"

"5";"nach der Leerzeile";"22";"letzter Eintrag"
 [2009-05-18 18:49 UTC] iliaa@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.


 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Apr 14 05:01:24 2021 UTC