Skip to main content

Module csv

Module csv 

Source
Expand description

CSV parsing: str_getcsv() and fgetcsv().

A port of php_fgetcsv() (ext/standard/file.c, PHP 8.5): fields are split at the delimiter; a field starting (after leading whitespace) with the enclosure runs to the closing enclosure, a doubled enclosure is one enclosure character, an escape character protects the next byte (and is kept), and text after the closing enclosure up to the delimiter is appended raw. Unenclosed fields lose trailing whitespace; the line’s trailing \r\n, \n or \r is dropped. An enclosure left open takes the following lines (fgetcsv()) or runs to the end of the input (str_getcsv()). A blank line is one null field.

Bytes are characters: the dev image’s C library counts one byte per character in the default locale, so no multibyte sequence is special.

Functions§

fgetcsv
PHP fgetcsv($stream, 0, $separator, $enclosure, $escape): the fields of the next record (an open enclosure takes the following lines), or None at the end of the stream (PHP’s false).
str_getcsv
PHP str_getcsv($string, $separator, $enclosure, $escape): the fields of input (an enclosure left open runs to the end); escape None is "" (no escape character).

Type Aliases§

Fields
One parsed line: its fields, or [null] (None) for a blank line.