dongwuwu6104 2012-03-08 20:03
浏览 14
已采纳

PHP String函数用于长条数据

i need to fetch data from the following strings and need to place their values according to their type

1) Response: Success Message: Mailbox Message Count Mailbox: 6000 UrgMessages: 0 NewMessages: 5 OldMessages: 12

Required Output: example OLD= 12 NEW=5 URGENT=0

2) Name : 6000 Secret : MD5Secret : Context : DLPN_Admin Language : AMA flags : Unknown Transfer mode: open MaxCallBR : 384 kbps CallingPres : Presentation Allowed, Not Screened Call limit : 2147483647 Callgroup : 1 Pickupgroup : 1 Callerid : "Arham Ali" <6000> ACL : No Sess-Timers : Accept Sess-Refresh : uas Sess-Expires : 1800 secs Sess-Min-SE : 90 secs Codec Order : (ulaw:20,gsm:20) Auto-Framing: No

Required Output: CallerId="Arham Ali" Name= "6000"

I am very much stuck with this stupid thing for so long please help me in PHP domain.

  • 写回答

2条回答 默认 最新

  • doupuchen6378 2012-03-08 20:17
    关注

    If you need a bit more incase the message string is not always the same you could do this

    $string = ' Response: Success Message: Mailbox Message Count Mailbox: 6000 UrgMessages: 0 NewMessages: 5 OldMessages: 12';
    
    
    preg_match('/OldMessages: (\d+)*/', $string, $oldMessages);
    preg_match('/NewMessages: (\d+)*/', $string, $newMessages);
    preg_match('/UrgMessages: (\d+)*/', $string, $urgent);
    preg_match('/Mailbox: (\d+)*/', $string, $currentMailboxCount);
    
    print 'OLD= '.$oldMessages[1].' NEW='.$newMessages[1].' URGENT='.$urgent[1];
    

    This is all using regex. preg_match

    The same methods would apply for the second half of your question.

    A good tool to play with regex is http://gskinner.com/RegExr/

    Hoep this helps you out!

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

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集