PHP str_getcsv() Function

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/*from  ww w .  j a v  a  2s.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.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions