ID: 42358 Updated by: [EMAIL PROTECTED] Reported By: guillaume dot lecanu at noovea dot fr -Status: Open +Status: Feedback -Bug Type: Unknown/Other Function +Bug Type: *General Issues Operating System: linux ubuntu feisty PHP Version: 5.2.3 New Comment:
So in your case: use the 4th parameter like this: while (($row = fgetcsv($handle, 100, "\t", "\t")) !== FALSE) { With that I get your expected result. (enclosure defaults to ") Previous Comments: ------------------------------------------------------------------------ [2007-08-21 09:37:13] guillaume dot lecanu at noovea dot fr Description: ------------ In a TSV (Tab Separated Values) file where every values are not encapsuled by quotes ; if a value start by a quote, the value is wrong, all next lines are get in this field (see my example). (I can't upgrade in 5.2.3 to test, but this bug was under PHP 4.3.10-16 and still here in PHP 5.2.1). Reproduce code: --------------- <?php $file = "fgetcsv_bug.txt"; $handle = fopen($file, "r"); if (!$handle) { die("File {$file} not found !"); } $nb_rows = 0; while (($row = fgetcsv($handle, 100, "\t")) !== FALSE) { echo "<br>ROW ".( ++$nb_rows )." : "; var_export($row); } ?> The fgetcsv_bug.txt is a simple file where values are tab separated : A1 A2 A3 A4 B1 "B2 B3 B4 C1 C2 C3 C4 D1 D2 D3 D4 Expected result: ---------------- ROW 1 : array ( 0 => 'A1', 1 => 'A2', 2 => 'A3', 3 => 'A4', ) ROW 2 : array ( 0 => 'B1', 1 => '"B2', 2 => 'B3', 3 => 'B4', ) ROW 3 : array ( 0 => 'C1', 1 => 'C2', 2 => 'C3', 3 => 'C4', ) ROW 4 : array ( 0 => 'D1', 1 => 'D2', 2 => 'D3', 3 => 'D4', ) Actual result: -------------- ROW 1 : array ( 0 => 'A1', 1 => 'A2', 2 => 'A3', 3 => 'A4', ) ROW 2 : array ( 0 => 'B1', 1 => 'B2 B3 B4 C1 C2 C3 C4 D1 D2 D3 D4 ', ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42358&edit=1