From: guillaume dot lecanu at noovea dot fr
Operating system: linux ubuntu feisty
PHP version: 5.2.3
PHP Bug Type: Unknown/Other Function
Bug description: fgetcsv bug on TSV file if a field start by a quote
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 bug report at http://bugs.php.net/?id=42358&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=42358&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=42358&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=42358&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=42358&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=42358&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=42358&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=42358&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=42358&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=42358&r=support
Expected behavior: http://bugs.php.net/fix.php?id=42358&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=42358&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=42358&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=42358&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42358&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=42358&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=42358&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=42358&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=42358&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=42358&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=42358&r=mysqlcfg