what is explode in php
<?php
$str = 'one,two,three,four';
// to get all of the numbers: [one, two, three, four]
$numbers1 = explode(',',$str)
// same as $str
$numbers2 = explode(',',$str,0);
// breakes the string into two parts
$numbers3 = explode(',',$str,2);
// the last result will be removed
$numbers4 = explode(',',$str,-1);
?>
/* The explode() function breaks a string into an array.
Note: The "separator" parameter cannot be an empty string. */
syntax:
explode(separator,string,limit);
<html>
<body>
<?php
$str = 'one,two,three,four';
// zero limit
print_r(explode(',',$str,0));
print "<br>";
// positive limit
print_r(explode(',',$str,2));
print "<br>";
</body>
</html>
<output>
Array ( [0] => one,two,three,four )
Array ( [0] => one [1] => two,three,four )
<?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; // *
?>