php explode 多个分隔符使用方法

php教程8年前 (2017-04-17)18820
php使用explode拆分含多个分隔符的字符串,分隔字符串为数组
 
方法一:先将分隔符转换成统一字符,再使用explode进行拆分

1$arr=explode('#',str_replace(array(":"),'#',$string));

方法二:使用preg_split拆分

1$string="php教程#php入门:教程#字符串:多分隔符#字符串:拆分#数组";
2$arr = preg_split("/(#|:)/",$string);
3print_r($arr);



输出结果:
Array
(
    [0] => php教程
    [1] => php入门
    [2] => 教程
    [3] => 字符串
    [4] => 多分隔符
    [5] => 字符串
    [6] => 拆分
    [7] => 数组
)                      


标签: explode

“php explode 多个分隔符使用方法” 的相关文章

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。