Bug #13950 Updated: fgetcsv misinterprets fields containing double-quotes

From: Date: Thu, 08 Nov 2001 19:34:20 +0000
Subject: Bug #13950 Updated: fgetcsv misinterprets fields containing double-quotes
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-69825@lists.php.net to get a copy of this message
ID: 13950 User updated by: liamr@umich.edu Reported By: liamr@umich.edu Status: Open Bug Type: Filesystem function related Operating System: Sun (SPARC) Solaris 2.6 Old PHP Version: 4.0.6 PHP Version: 4.0.6 / 4.20cvs New Comment: I tried it with the copy of PHP in CVS. It's a problem in that version too. Previous Comments: ------------------------------------------------------------------------ [2001-11-06 00:23:31] liamr@umich.edu 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 this bug report at http://bugs.php.net/?id=13950&edit=1

« previous php.dev (#69825) next »