PHP preg_mahch character interception solution ideas

Source: Internet
Author: User
PHP preg_mahch character interception
PHP Code
  
   $tt = "Event:dial  privilege:call,all  subevent:begin  Channel: [Email protected];2  destination:sip/ 601-00001BCA  calleridnum:07016317212  calleridname:rc07016317212  connectedlinenum:0267  connectedlinename:0267  uniqueid:1339380988.50590  destuniqueid:1339380988.50591  dialstring:601 "; Preg_match ("/(calleridnum:\s+\d+) \s+.+ (uniqueid:\s\d+\.\d+)/", $tt, $out, preg_offset_capture,3);

Hopefully the result is
[' Calleridnum '] =〉 "07016317212";
[' calleridname '] = "rc07016317212";
[' Connectedlinenum ']=> "0267";
[' Connectedlinename ']=> "0267";
[' UniqueID ']=> "1339380988.50590";
[destuniqueid]=> "1339380988.50591";
。。。。。。。。。
Type So, splitting a name from that string corresponds to a value

------Solution--------------------
PHP Code
$tt = "Event:dial privilege:call,all subevent:begin Channel: [Email protected];2 destination:sip/601-00001bca Cal leridnum:07016317212 calleridname:rc07016317212 connectedlinenum:0267 connectedlinename:0267 uniqueid:1339380988. 50590 destuniqueid:1339380988.50591 dialstring:601 ";p reg_replace ('/(\w+): \s+ ([^\s]+)/E ', ' $ar [$1]=" "$" ', $tt);// Quit ();p Rint_r ($ar);
------Solution--------------------
PHP Code
[User:root time:13:15:35 path:/home/liangdong/php]$ Cat preg.php
    [User:root time:13:15:36 path:/home/liangdong/php]$ php preg.php Array ([0] = = Array ([0] + = C            alleridnum:07016317212 [1] = calleridname:rc07016317212 [2] = connectedlinenum:0267  [3] = = connectedlinename:0267 [4] = uniqueid:1339380988.50590 [5] = = Destuniqueid: 1339380988.50591 [6] = dialstring:601) [1] = = Array ([0] = Calleridn            um [1] = calleridname [2] = connectedlinenum [3] = = Connectedlinename        [4] = = UniqueID [5] = Destuniqueid [6] = dialstring) [2] = = Array             ([0] = 07016317212 [1] = rc07016317212 [2] = 0267 [3] = 0267 [4] = = 1339380988.50590 [5] = 1339380988.50591 [6] = 601))
------Solution--------------------
Change my \s+ to \s*.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.