Bug #12556: fgetcsv ignores length if quotes not closed
| From: | brianm at dealnews dot com | Date: | Fri, 03 Aug 2001 16:45:29 +0000 |
| Subject: | Bug #12556: fgetcsv ignores length if quotes not closed | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-61985@lists.php.net to get a copy of this message | ||
From: brianm@dealnews.com
Operating system: Linux
PHP version: 4.0.6
PHP Bug Type: Filesystem function related
Bug description: fgetcsv ignores length if quotes not closed
Ok, I can live with the embedded newlines in fgetcsv even though I think it
is wrong. No other app will read a csv file this way. MySQL for example
exports a literal \n for newlines and translates them on import rather than
embedding them.
But, I do think the length should be respected no matter what:
data:
-----------------
6,7,8,line1
1,2,3,"line2
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
script:
---------------
$fp=fopen("test.csv", "r");
while($line=fgetcsv($fp, 24)){
print_r($line);
}
Nothing after that quote gets read. Even after 24 bites have been read.
It would seem to me that the code which reads an additional line if an
embedded newline is reached should not issue an FP_FGETS with len but
should use len-strlen(temp). This would make the length param make more
sense. And then if len was met it should terminate the record and start
all over.
The code in this function is less that understandable with all the great
names like buff and temp floating around. I tried looking at it but will
leave it to the guys who wrote it.
--
Edit bug report at: http://bugs.php.net/?id=12556&edit=1