(PHP 3, PHP 4, PHP 5) explode -- use one string to separate the description of another string
Array explode (string separator, string [, int limit])
This function returns an array composed of strings. Each element is a substring of a string, which is separated by a string separator as a boundary point.
If the limit parameter is set, the returned array contains up to limit elements, and the last element contains the rest of the string.
If separator is a null string (""), explode () returns false.
If the value of separator cannot be found in string, explode () returns an array containing a single string element.
If the limit parameter is negative, all elements except the last limit element are returned. This feature is added in PHP 5.1.0.
For historical reasons, although implode () can receive two parameter sequences, explode () cannot. You must ensure that the separator parameter is prior to the string parameter.
Note: The limit parameter is added to PhP 4.0.1.
Example 1.
Explode () Example
// Example 1
$ Pizza = "piece1 piece2 piece3 piece4 piece5 piece6 ";
$ Pieces = explode ("", $ pizza );
Echo $ pieces [0]; // piece1
Echo $ pieces [1]; // piece2
// Example 2
$ Data = "foo: *: 1023: 1000:/home/foo:/bin/sh ";
List ($ user, $ pass, $ uid, $ gid, $ gecos, $ home, $ shell) = explode (":", $ data );
Echo $ user; // foo
Echo $ pass ;//*
Example 2.
Limit parameter example
$ Str = 'one | two | three | four '; // positive number
Limit print_r (explode ('|', $ str, 2); // negative
Limit print_r (explode ('|', $ str,-1 ));
The above example will be output:
Array ([0] => one [1] => two | three | four) array ([0] => one [1] => two [2] => Three)
Note: this function can be safely used for binary objects.