Bug #13950: fgetcsv misinterprets fields containing double-quotes
| From: | liamr at umich dot edu | Date: | Tue, 06 Nov 2001 05:23:32 +0000 |
| Subject: | Bug #13950: fgetcsv misinterprets fields containing double-quotes | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-69687@lists.php.net to get a copy of this message | ||
From: liamr@umich.edu
Operating system: Sun (SPARC) Solaris 2.6
PHP version: 4.0.6
PHP Bug Type: Filesystem function related
Bug description: fgetcsv misinterprets fields containing double-quotes
I'm trying to write a script to interpret pine-style addressbooks, which
are pretty much just full tab-seperated values.. It doesn't handle fields
with double quotes correctly. If the field starts with a quotes, it strips
them, and removes any data that follows the closing quote for that field.
This code and data will replicated the problem.
<?php
$row = 1;
$fh = fopen("./addressbook","r");
while ($data = fgetcsv ($fh, 1000, "\t")) {
$num = count($data);
$match = preg_grep("/(#|\(|\))/", $data);
if ( ($num < 3) || (count($match) >=1) ) {
continue;
}
print "\n$num fields in line $row:\n";
$row++;
for ($c=0; $c<$num; $c++) {
print $data[$c] . "\n";
}
}
fclose ($fh);
?>
"addressbook" is a tab separated file containing data along the lines of:
liamr Hoekenga, Liam liamr@umich.edu
liam "Liam Hoekenga" liam.hoekenga@umich.edu
lhoek "Liam H." "Liam R. Hoekenga" <liamr@umich.edu>
lrh ME "ME" ME liamr@umich.edu
lrh1 "ME" ME liamr@umich.edu
produces this output:
3 fields in line 1:
liamr
Hoekenga, Liam
liamr@umich.edu
3 fields in line 2:
liam
Liam Hoekenga
liam.hoekenga@umich.edu
3 fields in line 3:
lhoek
Liam H.
Liam R. Hoekenga
3 fields in line 4:
lrh
ME "ME" ME
liamr@umich.edu
3 fields in line 5:
lrh1
ME
liamr@umich.edu
--
Edit bug report at: http://bugs.php.net/?id=13950&edit=1