Menu Samaritan's Purse

EXPLODE

Split a string by a string

SYNTAX

explode ( string $delimiter , string $string [, int $limit = PHP_INT_MAX ] ) : array

PARAMETERS

delimiter

The boundary string.

string

The input string.

limit

If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string. If the limit parameter is negative, all components except the last -limit are returned. If the limit parameter is zero, then this is treated as 1.

Note: Although implode() can, for historical reasons, accept its parameters in either order, explode() cannot. You must ensure that the delimiter argument comes before the string argument.

RETURN

Returns an array of strings created by splitting the string parameter on boundaries formed by the delimiter. If delimiter is an empty string (""), explode() will return FALSE. If delimiter contains a value that is not contained in string and a negative limit is used, then an empty array will be returned, otherwise an array containing string will be returned.

EXAMPLES

DELIMITER | COMMA

Array
(
    [0] => word1
    [1] => word2
    [2] => word3
    [3] => word4
    [4] => word5
)

DELIMITER | NEWLINE

Array
(
    [0] => word1
    [1] => word2
    [2] => word3
    [3] => word4
    [4] => word5
)

DELIMITER | SPACE

Array
(
    [0] => word1
    [1] => word2
    [2] => word3
    [3] => word4
    [4] => word5
)

DELIMITER | EMPTY


STRING | EMPTY

Array
(
    [0] =>
)

STRING | 1 DELIMITER

Array
(
    [0] =>
    [1] =>
)

STRING | 1 ELEMENT

Array
(
    [0] => word1
)

STRING | 1 ELEMENT 1 DELIMITER

Array
(
    [0] => word1
    [1] =>
)

LIMIT | -2

Array
(
    [0] => word1
    [1] => word2
    [2] => word3
)

LIMIT | -1

Array
(
    [0] => word1
    [1] => word2
    [2] => word3
    [3] => word4
)

LIMIT | 0

Array
(
    [0] => word1 word2 word3 word4 word5
)

LIMIT | 1

Array
(
    [0] => word1 word2 word3 word4 word5
)

LIMIT | 2

Array
(
    [0] => word1
    [1] => word2 word3 word4 word5
)

LIMIT | PHP_INT_MAX

Array
(
    [0] => word1
    [1] => word2
    [2] => word3
    [3] => word4
    [4] => word5
)

RETURN | ARRAY

Array
(
    [0] => word1
    [1] => word2
    [2] => word3
    [3] => word4
    [4] => word5
)

RETURN | ARRAY INDEX

word1
word2
word3
word4
word5

RETURN | LIST VARIABLE

word1
word2
word3
word4
word5

PHP