Beata Go.
0
Q:

explode php

$colors  = "red,blue,green,orange";
$colorsArray = explode(",", $colors);
20

<?php

$str = "Hello world. It's a beautiful day.";

print_r (explode(" ",$str));

?> 
0

 <?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);
?> 
 
6
$str = 'one two three four';
$numbers4 = explode(' ',$str);
2
/*  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 )  
 
0

<?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; // *

?>

0

New to Communities?

Join the community