ID: 44074
Updated by: [EMAIL PROTECTED]
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:
Hello, note that the escape character default is the backslash. Change
it to other character, and you'll the expected result.
Previous Comments:
------------------------------------------------------------------------
[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