Ok let it just for fun
$string = "here is a sample: this text, and this will be exploded. this also | this one too :)"; $needle = array(",",".","|",":"); $chars = implode($needle); $list = array(); while (false !== $match = strpbrk($string, $chars)) { $list[] = $match[0]; $string = substr($match, 1); } var_dump($list);
You can see his work - Read about strpbrk
Description
strpbrk
returns a string after the first matching character
Turn 1
$string = "here is a sample: this text, and this will be exploded. this also | this one too :)"; // strpbrk matches ":" $match = ": this text, and this will be exploded. this also | this one too :)"; // Then, we push the first character to the list ":" $list = array(':'); // Then we substract the first character from the string $string = " this text, and this will be exploded. this also | this one too :)";
Turn 2
$string = " this text, and this will be exploded. this also | this one too :)"; // strpbrk matches "," $match = ", and this will be exploded. this also | this one too :)"; // Then, we push the first character to the list "," $list = array(':', ','); // Then we substract the first character from the string $string = " and this will be exploded. this also | this one too :)";
And so on, until it works out
Turn 5
$string = ")";
Touki source share