|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-02-24 16:51 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 00:00:01 2025 UTC |
Description: ------------ Fgetcsv appears to have been rewritten from 4.3.4 which was a bit buggy. But there is still one unresolved issue with csv parsing I noticed in tests where the enclosure character is stripped from the text regardless of its enclosure status if it begins the string, but does not end the string. Reproduce code: --------------- Example file: blabla,"stuff with thing",yay foo,stuff with "thing",moo blarg,"stuff" with thing,goop Script: <?PHP $fp = fopen("/tmp/ctext.txt", "r"); while ($aLine = fgetcsv($fp, 8192, '|', '"')) { print_r($aLine); } fclose($fp); ?> Expected result: ---------------- Array ( [0] => blabla [1] => stuff with thing [2] => yay ) Array ( [0] => foo [1] => stuff with "thing" [2] => moo ) Array ( [0] => blarg [1] => "stuff" with thing [2] => goop ) Actual result: -------------- Note the missing quotes around "stuff" in the third array. I can only assume beginning the string with quotes makes PHP think the whole string is quoted, so it strips the first and second quotes it finds. Array ( [0] => blabla [1] => stuff with thing [2] => yay ) Array ( [0] => foo [1] => stuff with "thing" [2] => moo ) Array ( [0] => blarg [1] => stuff with thing [2] => goop )