PHP fgetcsv() Function

PHP fgetcsv Function


Definition :

The built-in fgetcsv() function parses a line from an open file and checks for CSV fields. This PHP function stops returning on a new line at a specified length or EOF, whichever comes first.

Syntax

   fgetcsv(filelengthseparatorenclosure)

Parameter 
Parameter Description
file Required. Specifies the open file to return and parse a line from
length Optional. 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. Note: This parameter is required in versions prior to PHP 5
separator Optional. Specifies the field separator. Default is comma ( , )
enclosure Optional. Specifies the field enclosure character. Default is "
escape Optional. Specifies the escape character. Default is "\\"

Given below example Read and output one line from the open CSV file:

Output : Array ( [0] => (This [1] => is [2] => demo [3] => csv [4] => file) )

Example2 : 

Output :

Array ( [0] => (This [1] => is [2] => demo [3] => csv [4] => file) )
Array ( [0] => This is demo csv file )