dongzhuxun5136 2013-03-19 11:46
浏览 126
已采纳

在PHP中将字符串拆分为数组的最快方法

I have a PHP script which splits strings into arrays using prey_split. The preg_split code is:

preg_split("~(?<!\*):~", $val);

Which essentially splits the string where there is a colon, without a preceding asterisk. For example: "h*:el:lo" turns into array("h*:el", "lo")

This process is quite resource intensive and slow when splitting large amounts of strings. Is there a faster method to achieve this?

  • 写回答

2条回答 默认 最新

  • dounangshen6553 2013-03-19 12:54
    关注

    Are you required to use preg_split()? Because it's easier to use preg_match_all():

    preg_match_all('/(?:^|:)([^*:]+(?:\*.[^*:]+)*)/', $subject, $result, PREG_PATTERN_ORDER);
    $result = $result[1];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)