PHP fgetcsv() Function

The fgetcsv() function parses a line from an open file, checking for CSV fields.The fgetcsv() function stops returning on a new line, at the specified length, or at EOF, whichever comes first.This function returns the CSV fields in an array on success, or FALSE on failure and EOF.

array fgetcsv ( resource $handle [, int $length = 0 [, string $delimiter = "," [, string $enclosure = '"' [, string $escape = "\\" ]]]] )

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

Example -

ParameterDescription
fileRequired. Specifies the file to check
lengthOptional. Specifies the maximum length of a line. Must be greater than the longest line (in characters) in the CSV file. Omitting this parameter (or setting it to 0) the line length is not limited, which is slightly slower.
separatorOptional. A character that specifies the field separator. Default is comma ( , )
enclosureOptional. A character that specifies the field enclosure character. Default is "