str_getcsv

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

addcslashes

addslashes

bin2hex

chop

chr

chunk_split

convert_uudecode

convert_uuencode

count_chars

crc32

crypt

echo

explode

fprintf

get_html_translation_table

hebrev

hebrevc

hex2bin

html_entity_decode

htmlentities

htmlspecialchars

htmlspecialchars_decode

implode

join

lcfirst

levenshtein

localeconv

ltrim

md5

md5_file

metaphone

nl_langinfo

nl2br

number_format

ord

parse_str

print

printf

quoted_printable_decode

quoted_printable_encode

quotemeta

rtrim

setlocale

sha1

sha1_file

similar_text

soundex

sprintf

sscanf

str_contains

str_ends_with

str_ireplace

str_pad

str_repeat

str_replace

str_rot13

str_shuffle

str_split

str_starts_with

str_word_count

strcasecmp

strchr

strcmp

strcoll

strcspn

strip_tags

stripcslashes

stripos

stripslashes

stristr

strlen

strnatcasecmp

strnatcmp

strncasecmp

strncmp

strpbrk

strpos

strrchr

strrev

strripos

strrpos

strspn

strstr

strtok

strtolower

strtoupper

strtr

substr

substr_compare

substr_count

substr_replace

trim

ucfirst

ucwords

vfprintf

vprintf

vsprintf

wordwrap

External

PHP

Home Menu