duanbo1659 2015-01-22 12:13
浏览 36
已采纳

如何拆分组合字符串

I have a string which looks like this:

21/04/2014,16:57:28,19,0,2021/04/2014,16:57:48,19,0,20

I would like to split it so that I get something like the following:

21/04/2014,16:57:28,19,0,20
21/04/2014,16:57:48,19,0,20

I have tried using php's substr which I thought was giving results but it duplicated this '21/04/2014,16:57:48,19,0,20' twice.

$data3 = array(substr($data1, -27), substr($data1, 27));

Even tried a regex with no luck.

  • 写回答

3条回答 默认 最新

  • dongtan9253 2015-01-22 12:23
    关注

    Elon Than's answer is the perfect solution if, as he states, the length is constant. However, I just thought I'd add this solution in case (for example) the '19' could also be '3' (or whatever):

    preg_match_all("/\d{2}\/\d{2}\/\d{4}\,\d{2}:\d{2}:\d{2},\d{1,2},\d{1},\d{2}/", $string, $matches);
    
    var_dump($matches[0]);
    

    Notice the \d{1,2} will include any number that is 1 or 2 digits.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错