Handling unlimited number of explodes

by Nirmala 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));
?>

Tagged in:

1255
like
1
dislike
0
mail
flag

You must LOGIN to add comments