65F*_*f05 56
$str = 'Monsters are SUPER scary, bro!';
$del = array('a', 'b', 'c');
// In one fell swoop...
$arr = explode( $del[0], str_replace($del, $del[0], $str) );
Run Code Online (Sandbox Code Playgroud)
Ign*_*ams 29
使用preg_split()适当的正则表达式.
function explode_by_array($delim, $input) {
$unidelim = $delim[0];
$step_01 = str_replace($delim, $unidelim, $input); //Extra step to create a uniform value
return explode($unidelim, $step_01);
}
Run Code Online (Sandbox Code Playgroud)
那改进了@ 65Fbef05的代码.我们使用第一个分隔符,因为"+delim+"可以在原始字符串中使用.