Definition and usage
explode() function splits a string into an array.
Syntax
Parameters | Description |
---|---|
separator | Required. Specifies where to split the string. |
string | Required. The string to split. |
limit | optional. Specifies the maximum number of array elements returned. |
Explanation
This function returns an array composed of strings, each element of which is a substring separated by separator as a boundary point.
separator parameter cannot be an empty string. If separator is the empty string (""), explode() will return FALSE. If separator contains a value not found in string , then explode() will return an array containing a single element in string .
If the limit parameter is set, the returned array contains up to limit elements, and the last element will contain the remainder of the string.
If the limit parameter is negative, all elements except the last -limit elements are returned. This feature is new in PHP 5.1.0.
Tips and Notes
Note: The limit parameter was added in PHP 4.0.1.
Note: Due to historical reasons, although implode() can receive two parameter orders, explode() cannot. You must ensure that the separator parameter comes before the string parameter.
Example
In this example, we will split the string into an array:
Output:
Copyright statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.
The above introduces the PHP explode function, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.