Home > PHP > Function > Filesystem > fgetcsv()

fgetcsv()

fgetcsv - Gets line from file pointer and parse for CSV fields

Syntax

array fgetcsv (resource $handle, int $length, string $delimiter, string $enclosure, string $escape)

Arguments

  • handle - A valid file pointer to a file successfully opened by fopen(), popen(), or fsockopen().
  • length - Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters). It became optional in PHP 5. Omitting this parameter (or setting it to 0 in PHP 5.0.4 and later) the maximum line length is not limited, which is slightly slower.
  • delimiter - Set the field delimiter (one character only).
  • enclosure - Set the field enclosure character (one character only).
  • escape - Set the escape character (one character only). Defaults as a backslash.

Description

Similar to fgets() except that fgetcsv() parses the line it reads for fields in CSVformat and returns an array containing the fields read.

Version

PHP 4, 5

Return value

Returns an indexed array containing the fields read.