Javatpoint Logo
Javatpoint Logo

PHP string str_getcsv() Function

The str_getcsv() is in-built PHP string function. It is important function which is used to parse a CSV string into an array.

Syntax:

Parameter Description Required/Optional
string Specify the string to parse. Default is comma ( , ). Required.
separator Specify the field separator. Default is ". Optional
enclosure Specify the field enclosure character. Default is ". Optional
escape Specify the escape character. Default is backslash (\). escape
PHP string str_getcsv Function

Example 1

//Create 'data.csv' File

Output:

Note: If "data.csv" file is not found then it will return error.

Example 2

// create "data.csv" and save :

PHP string Function

//Save it: test.php

Output:

Array ( 
	[0] => 101 
	[1] => Alok Nandan 
	[2] => is 
	[3] => Learning 
	[4] => PHP 
	[5] => from 
	[6] => JavaTpoint 
	)

Example 3

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 String





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