本文介绍了PHP多个分隔符爆炸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题,我有一个字符串数组,我想用不同的定界符爆炸.例如
I have a problem, I have a string array, and I want to explode in different delimiter. For Example
$example = 'Appel @ Ratte';
$example2 = 'apple vs ratte'
我需要一个在@或vs中爆炸的数组.
and I need an array which is explode in @ or vs.
我已经写了一个解决方案,但是如果每个人都有更好的解决方案,请在此处发布.
I already wrote a solution, but If everybody have a better solution please post here.
private function multiExplode($delimiters,$string) {
$ary = explode($delimiters[0],$string);
array_shift($delimiters);
if($delimiters != NULL) {
if(count($ary) <2)
$ary = $this->multiExplode($delimiters, $string);
}
return $ary;
}
推荐答案
使用
$output = preg_split( "/ (@|vs) /", $input );
这篇关于PHP多个分隔符爆炸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!