#44074 [NEW]: fgetcsv incorrect parse

From: Date: Thu, 07 Feb 2008 20:37:24 +0000
Subject: #44074 [NEW]: fgetcsv incorrect parse
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-122081@lists.php.net to get a copy of this message
From: felixl at densi dot com Operating system: Windows XP SP2 & linux PHP version: 5.2.5 PHP Bug Type: Streams related Bug description: fgetcsv incorrect parse Description: ------------ a csv file with 5 columns. note the ^M in data, it's suppose to be there note the \" line incorrect parse of the line with the \" remove the \ and the parse is correct. As per csv doc, when inside a quote string ("), enter, ^M or anything else then " is consider data. PS. I wanted to attach my files but it seems there is no way to do that. So you might not see the ^M character in the test file. Reproduce code: --------------- test file (test.csv): 050855,0,20071114,19:01:08,"Don returned my call. We had a nice talk about things. He is slowing down a bit. He said he got his order and the drums were a little better wrapped. \" 050855,0,20071220,11:33:44,"nice call with Don. He's pretty lonely right now." 050855,0,20071220,12:39:16,finally e-mailed him... 050855,0,20080108,10:31:00,"I calle Don and we chatted for a bit." script (readcsv.php): <?php $numFields = $argv[1]; $file = $argv[2]; print "numFields: $numFields\n"; print "Filename: $file\n"; $num = 0; $limit = 200; $handle = fopen($file, 'r'); while (($arr = fgetcsv($handle)) !== false) { $num++; if ($num % $limit == 0) { print "$num\n"; } if (count($arr) != $numFields) { print "Invalid number of column at $num\n"; print_r($arr); exit; } } fclose($handle); print "Done\n"; exit; ?> usage: php readcsv.php 5 test.csv Expected result: ---------------- numFields: 5 Filename: fgetcsv\test.csv Done Actual result: -------------- numFields: 5 Filename: fgetcsv\test.csv Invalid number of column at 2 Array ( [0] => He's pretty lonely right now." ) -- Edit bug report at http://bugs.php.net/?id=44074&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=44074&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44074&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44074&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44074&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44074&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44074&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44074&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44074&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44074&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44074&r=support Expected behavior: http://bugs.php.net/fix.php?id=44074&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44074&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44074&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44074&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=44074&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=44074&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44074&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44074&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44074&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44074&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44074&r=mysqlcfg

« previous php.bugs (#122081) next »