Copy Code code as follows:
$a = "string";
$c = Explode ("Text to be deleted", $a, 2);
$b = $c [0]. $c [1];
Explode
(PHP 3, PHP 4, PHP 5)
Explode--dividing another string with one string
Describe
Array explode (string separator, string string [, int limit])
This function returns an array of strings, each of which is a substring of string, which is split by separator as a boundary point. 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 separator is an empty string (""), Explode () returns FALSE. If the value contained in separator is not found in string, explode () returns an array that contains a single element of string.
If the limit parameter is a negative number, all elements except the last limit element are returned. This feature is new in the PHP 5.1.0.
For historical reasons, although implode () can receive two parameter orders, explode () is not. You must ensure that the separator parameter is not preceded by a string parameter.
Note: The parameter limit is added in the PHP 4.0.1.
Example 1. Explode () example
Copy Code code as follows:
<?php
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
Copy Code code as follows:
<?php
$str = ' One|two|three|four ';
Limit of positive numbers
Print_r (Explode (' | ', $STR, 2));
Limit of negative numbers
Print_r (Explode (' | ', $STR,-1));
?>
The above example outputs:
Array
(
[0] => One
[1] => Two|three|four
)
Array
(
[0] => One
[1] => two
[2] => three
)
Note: This function can be used safely for binary objects.