#28869 [NEW]: possible wrong behavior of fgetcsv (?)

From: Date: Mon, 21 Jun 2004 14:58:09 +0000
Subject: #28869 [NEW]: possible wrong behavior of fgetcsv (?)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-61156@lists.php.net to get a copy of this message
From: laph at gmx dot net Operating system: All PHP version: 4.3.6 PHP Bug Type: Filesystem function related Bug description: possible wrong behavior of fgetcsv (?) Description: ------------ Assume a file with 1 line of text (toImport.csv) and a [newline] after the last char in that line. The code below will echo "2" (Lines) using either fgets or fgetcsv. While this is right for fgets, it's wrong for fgetcsv (I think), because in CSV-Files the [newline] (logically) terminates a row, it doesn't start a new one - at least if you think of a CSV-File as a Recordset from a SQL-Statement (If you read the last "line" of a SQL-Result, move the Row-Pointer to the next row and try to read it, you'll get false/EOF and not a row with 0 elements). If you return the Array "$data" in each iteration you get a array with (int) 0 elements as last row, what makes using a loop until EOF impossible, because you (additionally) have to check the number of elements returned in $data. It's quite anoying, that fgetcsv makes difference if a csv-file is terminated by a newline or not. Reproduce code: --------------- $fh = fopen(dirname(__FILE__)."/toImport.csv","r"); $row = 0; while (!feof($fh)) { $data = fgetcsv($fh,1000,";"); // $data = fgets($fh,1000); $row++; } echo($row); Expected result: ---------------- fgetcsv should echo 1, while fgets should echo 2 -- Edit bug report at http://bugs.php.net/?id=28869&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28869&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28869&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=28869&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=28869&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=28869&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=28869&r=needscript Try newer version: http://bugs.php.net/fix.php?id=28869&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=28869&r=support Expected behavior: http://bugs.php.net/fix.php?id=28869&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=28869&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=28869&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=28869&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28869&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=28869&r=dst IIS Stability: http://bugs.php.net/fix.php?id=28869&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=28869&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=28869&r=float

« previous php.bugs (#61156) next »