PHP 8.5.0 Alpha 1 available for testing

Voting

: min(two, six)?
(Example: nine)

The Note You're Voting On

junk at vhd dot com dot au
19 years ago
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.

<< Back to user notes page

To Top