是否有一种使用爆炸功能的方式只能通过最后的分米发生?
$string = "one_two_ ... _three_four"; $explodeResultArray = explode("_",$string);
结果应该是:
$expoldeResultArray[0] is "one_two_three ..."; $expoldeResultArray[1] is "four";
直截了当:
原文链接:https://www.f2er.com/php/132744.html$parts = explode('_',$string); $last = array_pop($parts); $parts = array(implode('_',$parts),$last); echo $parts[0]; // outputs "one_two_three"
正则表达式:
$parts = preg_split('~_(?=[^_]*$)~',$string); echo $parts[0]; // outputs "one_two_three"
字符串反向:
$reversedParts = explode('_',strrev($string),2); echo strrev($reversedParts[0]); // outputs "four"