ID: 28869 Updated by: [EMAIL PROTECTED] Reported By: laph at gmx dot net -Status: Open +Status: Bogus Bug Type: Filesystem function related Operating System: All PHP Version: 4.3.6 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php This is expected. Previous Comments: ------------------------------------------------------------------------ [2004-06-21 16:58:08] laph at gmx dot net 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 this bug report at http://bugs.php.net/?id=28869&edit=1
