Handling unlimited number of explodes
by Nirmala[ Edit ] 2009-10-31 11:35:10
Hi..
Use the below code to handle unlimited number of explodes.
function multi_explode($delimiters = array(), $string = '')
{
$result = array();
foreach ($delimiters as $delimiter)
if (!isset($array))
$array = explode($delimiter, $string);
else
foreach ($array as $key => $string)
$result[] = explode($delimiter, $string);
return $result;
}
$string = 'Hello
This is a test!
Explode this HELLO:THIS:IS:A:TEST
';
$delimiters = array('
', ':');
echo '
';
print_r(multi_explode($delimiters, $string));
?>