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:

ParameterDescriptionRequired/Optional
stringSpecify the string to parse. Default is comma ( , ).Required.
separatorSpecify the field separator. Default is ".Optional
enclosureSpecify the field enclosure character. Default is ".Optional
escapeSpecify 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




Latest Courses