Home » PHP str_getcsv() function

PHP str_getcsv() function

by Online Tutorials Library

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] => TutorAspire )  

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

You may also like