PHP Explode examples and tutorials
Array explode (string separator, string string [, int limit])
Separator required. Specify where to split the string.
String required. The string to split.
Limit optional. Specify the maximum number of array elements to return.
Each element is a substring of string, which is separated 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 package
Contains the remainder of a string.
If separator is an empty string (""), Explode () returns FALSE. If the separator package
Contains a value that is not found in string, then explode () returns an array containing a single element of string.
In this case, we'll split the string into arrays:
<?php
$STR = "Hello World". It ' s a beautiful day. ";
Print_r (Explode ("", $str));
?>
Array
(
[0] => Hello
[1] => world.
[2] => It ' s
[3] => a
[4] => Beautiful
[5] => day.
)
Example Two
<?php
Dividing a string into an array using the EXPLODE function
$source = "HELLO1,HELLO2,HELLO3,HELLO4,HELLO5";//separating strings by commas
$hello = Explode (', ', $source);
for ($index =0; $index <count ($hello); $index + +) {
echo $hello [$index];echo "</br>";
}
Example Three
<?php
$foo = ' uno dos tres '; Two spaces between "DOS" and "Tres"
Print_r (Explode (', $foo));
?>
Array
(
[0] => Uno
[1] => dos
[2] =>
[3] => Tres
)
Keep in mind that explode () can return, if separated immediately repeat two times (or more empty elements), as shown in the following
Example shows the following:
PHP Implode () function Instance Tutorial