Javatpoint Logo
Javatpoint Logo

PHP fgetcsv() Function

Thefgetcsv() function is used to get a line from file pointer and parse for CSV fields. Well, it is similar to fgets() function, but it parses the lines in CSV format, and it returns an array that contains the fields to read.

Syntax

Parameters

Parameter Description Required/Optional
File Specifies the file to check required
Length Specifies the maximum length of a line optional
separator specifies the field separator optional
enclosure specifies the field enclosure character optional

Returns

It returns an indexed array.

Example 1

Output:

Array ( [0] =>rosie [1] =>wan [2] =>starr [3] => Norway ) Array ( [0] =>somya [1] =>aksahy [2] =>dhanush [3] =>India ).

Example 2

Output:

Array ( [0] => 1 [1] => PEN [2] => red ) Array ( [0] => 2 [1] => Book [2] => green )
Or
Array ( 
[0] => 1
 [1] => PEN 
[2] => red 
)
 Array (
 [0] => 2
 [1] => Book 
[2] => green 
)
Next TopicPHP Filesystem





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA