Marcus Boerger wrote:
Hello David,
as promised i looked at the patch. Besides a small misstake it looks good. But it seems to work different then fgetcsv(). In other words if you write using fputcsv() you are not sure to get the same back with fgetcsv(). Though my current opinion is that fputcsv() is doing it right. The attached patch includes a testfile that demonstrates the problem.
anyone having thoughts?
I agree that if you write something with fputcsv() and then read it with fgetcsv() you should get back what you started with.
I don't see what's broken though. (Maybe I am misunderstanding your test cases.) The original array in the test file is:
+$list = array ( + 0 => 'aaa,bbb', + 1 => 'aaa,"bbb"', + 2 => '"aaa","bbb"', + 3 => 'aaa,bbb', + 4 => '"aaa",bbb', + 5 => '"aaa", "bbb"', + 6 => ',', + 7 => 'aaa,', + 8 => ',"aaa"', + 9 => '"",""', + 10 => '"""""",', + 11 => '""""",aaa', + 12 => 'aaa,bbb ', + 13 => 'aaa,"bbb "', + 14 => 'aaa"aaa","bbb"bbb', + 15 => 'aaa"aaa""",bbb', + 16 => 'aaa,"\\"bbb,ccc', + 17 => 'aaa"\\"a","bbb"', + 18 => '"\\"","aaa"', + 19 => '"\\""",aaa',
And then what gets printed out by fputcsv() is this: (which is different, but that's OK, since fputcsv() has worked its encoding magic):
+$list = array ( + 0 => 'aaa,bbb', + 1 => 'aaa,"""bbb"""', + 2 => '"""aaa""","""bbb"""', + 3 => 'aaa,bbb', + 4 => '"""aaa""",bbb', + 5 => '"""aaa"""," ""bbb"""', + 6 => ',', + 7 => 'aaa,', + 8 => ',"""aaa"""', + 9 => '"""""",""""""', + 10 => '"""""""""""""",', + 11 => '"""""""""""",aaa', + 12 => 'aaa,"bbb "', + 13 => 'aaa,"""bbb """', + 14 => '"aaa""aaa""","""bbb""bbb"', + 15 => '"aaa""aaa""""""",bbb', + 16 => 'aaa,"""\\""bbb",ccc', + 17 => '"aaa""\\""a""","""bbb"""', + 18 => '"""\\""""","""aaa"""', + 19 => '"""\\""""""",aaa', +);
And then this is the array after being read in by fgetcsv():
+$list = array ( + 0 => 'aaa,bbb', + 1 => 'aaa,"bbb"', + 2 => '"aaa","bbb"', + 3 => 'aaa,bbb', + 4 => '"aaa",bbb', + 5 => '"aaa", "bbb"', + 6 => ',', + 7 => 'aaa,', + 8 => ',"aaa"', + 9 => '"",""', + 10 => '"""""",', + 11 => '""""",aaa', + 12 => 'aaa,bbb ', + 13 => 'aaa,"bbb "', + 14 => 'aaa"aaa","bbb"bbb', + 15 => 'aaa"aaa""",bbb', + 16 => 'aaa,"\\"bbb,ccc', + 17 => 'aaa"\\"a","bbb"', + 18 => '"\\"","aaa"', + 19 => '"\\""",aaa', +);
Which seems to be the same as the original array?
David
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php