#20716 [Opn->Csd]: fgetcsv() cannot handle multi-line input
| From: | iliaa@php.net | Date: | Sat, 30 Nov 2002 19:13:39 +0000 |
| Subject: | #20716 [Opn->Csd]: fgetcsv() cannot handle multi-line input | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-26253@lists.php.net to get a copy of this message | ||
ID: 20716
Updated by: iliaa@php.net
Reported By: edink@proventum.net
-Status: Open
+Status: Closed
Bug Type: Filesystem function related
Operating System: RedHat Linux 6.2
PHP Version: 4.3.0RC2
New Comment:
This bug has been fixed in CVS.
In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2002-11-29 05:00:01] edink@proventum.net
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',
),
)
------------------------------------------------------------------------
[2002-11-29 04:52:52] edink@proventum.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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20716&edit=1