Handling unlimited number of explodes - PHP Views : 468
Tagged in : PHP
1 0
Send mail
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));
?>

By Nirmala, On - 2009-10-31



    Login to add Comments .