PHP str_getcsv() Function
In this chapter you will learn:
- Definition for PHP str_getcsv() Function
- Syntax for PHP str_getcsv() Function
- Parameter for PHP str_getcsv() Function
- Return for PHP str_getcsv() Function
- Example - Get string value from a CSV line
Definition
The str_getcsv()
function parses a string for fields in CSV format
and returns an array containing the fields read.
Syntax
PHP str_getcsv() Function has the following syntax.
str_getcsv(string,separator,enclosure,escape)
Parameter
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 (\) |
Return
PHP str_getcsv() Function returns the CSV fields in an array.
Example
Get string value from a CSV line
<?php// java2s. co 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.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP str_ireplace() Function
- Syntax for PHP str_ireplace() Function
- Parameter for PHP str_ireplace() Function
- Return for PHP str_ireplace() Function
- Example - Replace the characters "WORLD" (case-insensitive) in the string "Hello world from java2s.com!" with "PHP"
- Example - Using str_replace() with an array and a count variable
- Example - Using str_replace() with less elements in replace than find
Home » PHP Tutorial » PHP String Functions