ID: 44074 User updated by: felixl at densi dot com Reported By: felixl at densi dot com Status: Open Bug Type: Streams related Operating System: Windows XP SP2 & linux PHP Version: 5.2.5 New Comment:
as per fgetcsv doc: php version 5.3.0 The escape parameter was added so it's not possible with version 5.2.5 also from wikipedia csv: http://en.wikipedia.org/wiki/Comma-separated_values However CSV differs from other delimiter separated file formats in using a " (double quote) character around fields that contain reserved characters so the default should be " and not \ Previous Comments: ------------------------------------------------------------------------ [2008-02-08 00:00:05] [EMAIL PROTECTED] Hello, note that the escape character default is the backslash. Change it to other character, and you'll the expected result. ------------------------------------------------------------------------ [2008-02-07 20:37:24] felixl at densi dot com 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 this bug report at http://bugs.php.net/?id=44074&edit=1
