|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-02-08 00:00 UTC] felipe@php.net
[2008-02-08 13:28 UTC] felixl at densi dot com
[2008-02-10 14:35 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 20:00:01 2025 UTC |
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." )