xxxxxxxxxx
Difference Between Php Explode() & Php Split()
The fundamental contrast between the explode() and split() methods is parting an enormous string.
Both methods are utilized to part a string.
Nonetheless, the split() work is utilized to part a string utilizing a normal articulation,
while the explode() function is utilized to part a string utilizing another string.
xxxxxxxxxx
<?php
// It doesnt get any better than this Example
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
xxxxxxxxxx
<?php
$str = "Hello Friend";
$arr1 = str_split($str);
$arr2 = str_split($str, 3);
print_r($arr1);
print_r($arr2);
?>
xxxxxxxxxx
<?php
$polygons = "monogon, digon, trigon, tetragon, pentagon"
#Now, I want to separate these polygon names
$separated = explode(", ", $polygons)
#SYNTAX:
# explode("using characters", Separate What)
?>
xxxxxxxxxx
$string = "Hello, World!";
$delimiter = ","; // Define the character or substring to split the string with
$array = explode($delimiter, $string);
print_r($array);
xxxxxxxxxx
<?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; // *
?>
xxxxxxxxxx
<?php
list($user, $pass, $uid, $gid, $extra) =
split(":", $passwd_line, 5);
?>
xxxxxxxxxx
$roots_includes = array(
'/functions/body-class.php',
'/functions/connections.php'
);
foreach($roots_includes as $file){
if(!$filepath = locate_template($file)) {
trigger_error("Error locating `$file` for inclusion!", E_USER_ERROR);
}
require_once $filepath;
}
unset($file, $filepath);