note 58124 added to function.fgetcsv
| From: | junk at vhd dot com dot au | Date: | Tue, 25 Oct 2005 04:52:46 +0000 |
| Subject: | note 58124 added to function.fgetcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-97542@lists.php.net to get a copy of this message | ||
The fgetcsv function seems to follow the MS excel conventions, which means:
- The quoting character is escaped by itself and not the back slash.
(i.e.Let's use the double quote (") as the quoting character:
Two double quotes "" will give a single " once parsed, if they are inside a
quoted field (otherwise neither of them will be removed).
\" will give \" whether it is in a quoted field or not (same for \\) , and
if a single double quote is inside a quoted field it will be removed. If it is not inside a
quoted field it will stay).
- leading and trailing spaces (\s or \t) are never removed, regardless of whether they are in quoted
fields or not.
- Line breaks within fields are dealt with correctly if they are in quoted fields. (So previous
comments stating the opposite are wrong, unless they are using a different PHP version.... I am
using 4.4.0.)
So fgetcsv if actually very complete and can deal with every possible situation. (It does need help
for macintosh line breaks though, as mentioned in the help files.)
I wish I knew all this from the start. From my own benchmarks fgetcsv strikes a very good compromise
between memory consumption and speed.
-------------------------
Note: If back slashes are used to escape quotes they can easily be removed afterwards. Same for
leading and trailing spaces.
----
Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58124
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58124&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58124&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58124&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58124&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58124&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58124&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58124&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58124&report=yes
Search -- http://master.php.net/manage/user-notes.php