Sunday, August 21, 2005

PHP explode function - string function

PHP explode function is a powerful and very useful php string function especially if you want to parse querystrings.

explode -- Split a string by use of a string separator, returns the parsed strings to array.

// Example 1
$yellow = "sponge1
sponge2 sponge3 sponge4 sponge5 sponge6";
$pieces = explode(" ", $yellow);
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; // *

?>

No comments: