Easy Tutorial
❮ Func Filesystem Set File Buffer Func Filesystem Fseek ❯

PHP fgetcsv() Function



Definition and Usage

The fgetcsv() function parses a line from an open file and checks for CSV fields.

The fgetcsv() function stops returning a new line when it reaches the specified length or the end of the file (EOF), whichever comes first.

The function returns the CSV fields as an array if successful, or FALSE if it fails or reaches the end of the file (EOF).

Syntax

Parameter Description
file Required. Specifies the file to check.
length Optional. Specifies the maximum length of a line. It must be greater than the longest line in the CSV file. If this parameter is omitted (or set to 0), there is no limit to the line length, although this may affect performance. Note: This parameter was required in versions of PHP prior to 5.
separator Optional. Sets the field delimiter (only one character allowed), with a default value of a comma ( , ).
enclosure Optional. Sets the field enclosure character (only one character allowed), with a default value of a double quotation mark ( " ).

Tips and Notes

Tip: See also the fputcsv() function.


Example 1

CSV File:

The above code will output:


Example 2

CSV File:

The above code will output:


❮ Func Filesystem Set File Buffer Func Filesystem Fseek ❯