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 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据