Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

str_getcsv

Description

The str_getcsv of String for PHP parse a CSV string into an array.

Syntax

str_getcsv ( string $input [, string $delimiter = "," [, string $enclosure = '"' [, string $escape = "\\" ]]] ) : array

Parameters

input

The string to parse.

delimiter

Set the field delimiter (one character only).

enclosure

Set the field enclosure character (one character only).

escape

Set the escape character (at most one character). Defaults as a backslash (\). An empty string ("") disables the proprietary escape mechanism.

Note: Usually an enclosure character is escaped inside a field by doubling it; however, the escape character can be used as an alternative. So for the default parameter values "" and \" have the same meaning. Other than allowing to escape the enclosure character the escape character has no special meaning; it isn't even meant to escape itself.

Return

Returns an indexed array containing the fields read.

Examples

1 · input

<?

$input = "a,b,c,d,e";

$return = str_getcsv($input);

print_r($return);

?>
Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => d
    [4] => e
)

2 · delimiter

<?

$input = "a b c d e";
$delimiter = " ";

$return = str_getcsv($input, $delimiter);

print_r($return);

?>
Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => d
    [4] => e
)

3 · enclosure

<?

$input = "a b 'c d' e";
$delimiter = " ";
$enclosure = "'";

$return = str_getcsv($input, $delimiter, $enclosure);

print_r($return);

?>
Array
(
    [0] => a
    [1] => b
    [2] => c d
    [3] => e
)

4 · escape

<?

$input = "a b 'c ''d''' e";
$delimiter = " ";
$enclosure = "'";
$escape = "'";

$return = str_getcsv($input, $delimiter, $enclosure, $escape);

print_r($return);

?>
Array
(
    [0] => a
    [1] => b
    [2] => c 'd'
    [3] => e
)

String

External

HomeMenu