方法一:先將分隔符轉換成統一字符,再使用explode進行拆分
$arr=explode('#',str_replace(array(":"),'#',$string));
方法二:使用preg_split拆分
$string="php教程#php入門:教程#字符串:多分隔符#字符串:拆分#數組"; $arr = preg_split("/(#|:)/",$string); print_r($arr);
輸出結果:
Array
(
[0] => php教程
[1] => php入門
[2] => 教程
[3] => 字符串
[4] => 多分隔符
[5] => 字符串
[6] => 拆分
[7] => 數組
)