The str_getcsv()
function parses a string for fields in CSV format
and returns an array containing the fields read.
PHP str_getcsv() Function has the following syntax.
str_getcsv(string,separator,enclosure,escape)
Parameter | Is Required | Description |
---|---|---|
string | Required. | String value to parse |
separator | Optional. | Field separator. Default is comma ( , ) |
enclosure | Optional. | Field enclosure character. Default is " |
escape | Optional. | Escape character. Default is backslash (\) |
PHP str_getcsv() Function returns the CSV fields in an array.
Get string value from a CSV line
<?php//from w w w. j a va2 s . c o m
$line = 'Demo "java2s.com." abc.jpg';
$parsed = str_getcsv(
$line, # Input line
' ', # Delimiter
'"', # Enclosure
'\\' # Escape char
);
var_dump( $parsed );
?>
The code above generates the following result.