加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

我们可以在PHP中的一行上做多个爆炸声明吗?

发布时间:2020-12-13 22:37:49 所属栏目:PHP教程 来源:网络整理
导读:我们可以在 PHP中进行多次explode()吗? 例如,要这样做: foreach(explode(" ",$sms['sms_text']) as $no)foreach(explode("",$sms['sms_text']) as $no)foreach(explode(",",$sms['sms_text']) as $no) 一体化爆炸像这样: foreach(explode('','',',$sms['s
我们可以在 PHP中进行多次explode()吗?

例如,要这样做:

foreach(explode(" ",$sms['sms_text']) as $no)
foreach(explode("&",$sms['sms_text']) as $no)
foreach(explode(",",$sms['sms_text']) as $no)

一体化爆炸像这样:

foreach(explode('','&',',$sms['sms_text']) as $no)

最好的方法是什么?我想要的是在一行中的多个分隔符上拆分字符串.

如果您希望将字符串拆分为多个分隔符,则可能需要 preg_split.
$parts = preg_split( '/(s|&|,)/','This and&this and,this' );
print_r( $parts );

结果如下:

Array ( 
  [0] => This 
  [1] => and 
  [2] => this 
  [3] => and 
  [4] => this 
)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读