|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-11-29 04:52 UTC] edink at proventum dot net
fgetcsv() was able to read multi-line fields that were quoted. Here is the example of the test file:
f1;f2;f3
Test 1a;Test 1b;Test 1c
Test 2a;"Test 2b - line 1
Test 2b - line 2
Test 2b - line 3";Test 2c
We are trying to parse this file with the following code:
$f = @fopen($argv[1], "r");
if (!$f) exit("Cannot open input file.\n");
$v = array();
while ($data = fgetcsv ($f, 10000, ";"))
{
$v[] = $data;
}
var_export($v);
Now, in PHP 4.2.3 and earlier this produces correct 3 element array. PHP 4.3.0-dev produces 5 element array because it gets confused with the multiple line input in the 2b field.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 UTC |
The correct output (4.2.3): array ( 0 => array ( 0 => 'f1', 1 => 'f2', 2 => 'f3', ), 1 => array ( 0 => 'Test 1a', 1 => 'Test 1b', 2 => 'Test 1c', ), 2 => array ( 0 => 'Test 2a', 1 => 'Test 2b - line 1 Test 2b - line 2 Test 2b - line 3', 2 => 'Test 2c', ), ) Incorrect output (4.3.0RC2): array ( 0 => array ( 0 => 'f1', 1 => 'f2', 2 => 'f3', ), 1 => array ( 0 => 'Test 1a', 1 => 'Test 1b', 2 => 'Test 1c', ), 2 => array ( 0 => 'Test 2a', 1 => 'Test 2b - line 1', ), 3 => array ( 0 => 'Test 2b - line 2', ), 4 => array ( 0 => 'Test 2b - line 3"', 1 => 'Test 2c', ), )