Home >>PHP String Functions >PHP str_getcsv() Function
PHP str_getcsv() function is used to parse any given CSV string into array. This function returns an array containing CSV fields read in it.
Syntax:
str_getcsv($string,$separator,$enclosure,$escape);
Parameter | Description |
---|---|
string | This is a required parameter. This parameter contains the string to be parsed. |
separator | This is an optional parameter. This parameter contains a character that specifies the field separator. |
enclosure | This is an optional parameter. This parameter contains a character that specifies the field enclosure character. |
escape | This is an optional parameter. This parameter contains a character that specifies the escape character. |
Here is an example of str_getcsv() Function in PHP:
<html> <body> <?php //create a 'csv' file. $file = array_map('str_getcsv', file('Jerry.csv')); ?> </body> </html>
<html> <body> <?php $CSVfp = fopen("Jerry.csv", "r"); if($CSVfp !== FALSE) { while(! feof($CSVfp)) { $data = fgetcsv($CSVfp, 1000, ","); print_r($data); } } fclose($CSVfp); ?> </body> </html>