Saturday, December 20, 2008

PHP: Function Explode

This function is used to break or split a string in php into a number of substrings based on the criteria you give. Like if you want to break a line into substrings with ':' as delimiters


$string = "anna:johnny:maria";

$pieces = explode(":",$string);

for($num=0 ; $num< count($pieces); $num++){
echo $pieces[$num]."
";
}

?>

You will have the output as an array of strings...

anna
johnny
maria

It is really useful function when dealing with html codes or fetching files from other sites

0 comments: