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