Php multiple delimiters in explode
Try about using:
$output = preg_split('/ (@|vs) /', $input);
You can take the first string, replace all the @
with vs
using str_replace
, then explode on vs
or vice versa.
function multiexplode ($delimiters,$string) {
$ready = str_replace($delimiters, $delimiters[0], $string);
$launch = explode($delimiters[0], $ready);
return $launch;
}
$text = "here is a sample: this text, and this will be exploded. this also | this one too :)";
$exploded = multiexplode(array(",",".","|",":"),$text);
print_r($exploded);
//And output will be like this:
// Array
// (
// [0] => here is a sample
// [1] => this text
// [2] => and this will be exploded
// [3] => this also
// [4] => this one too
// [5] => )
// )
Source: php@metehanarslan at php.net