note 95600 added to function.fgetcsv
| From: | thuejk at gmail dot com | Date: | Mon, 11 Jan 2010 21:47:25 +0000 |
| Subject: | note 95600 added to function.fgetcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164866@lists.php.net to get a copy of this message | ||
PHP's implementation does not follow RFC 4180 or Wikipedia's description, and does not
work in all cases with Excel or OO Calc, as described in bug http://bugs.php.net/bug.php?id=50686 .
Here is an RFC 4180-complient implementation in PHP. This can parse more than 1MiB of CSV text per
second, so while it obviously would be faster if written in C, it should be fast enough for most
uses.
It is fairly strict, in that it does not allow whitespace before the start of a quoted item, such as
1, "2" ,3 , in according to the standard, but it would be simple to make it laxer. It
supports both \r\n and \n linebreaks, where the standard only supports \r\n. whitespace is just
another data character, so '1, 2,3 ' becomes Array(1, " 2", "3 ").
backslashes are also just another character, as backslashes have no special meaning in RFC 4180.
Posted on my blog, since this comment section doesn't allow posts long enough to hold it: http://thuejk.blogspot.com/2010/01/
phps-implementation-of-fgetcsv-and.html . (Link in two parts, since the comment system won't
allow it in one as the line would be too long. PHP annoyance #324. Sometimes I wonder why I bother
with PHP.)
----
Server IP: 195.184.96.15
Probable Submitter: 83.221.149.227
----
Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php
Edit -- https://master.php.net/note/edit/95600
Del: integrated -- https://master.php.net/note/delete/95600/integrated
Del: useless -- https://master.php.net/note/delete/95600/useless
Del: bad code -- https://master.php.net/note/delete/95600/bad+code
Del: spam -- https://master.php.net/note/delete/95600/spam
Del: non-english -- https://master.php.net/note/delete/95600/non-english
Del: in docs -- https://master.php.net/note/delete/95600/in+docs
Del: other reasons-- https://master.php.net/note/delete/95600
Reject -- https://master.php.net/note/reject/95600
Search -- https://master.php.net/manage/user-notes.php