PHP preg_mahch character interception solution ideas

Source: Internet
Author: User
Tags preg
PHP preg_mahch character interception

PHP code

$tt = "Event:dial  privilege:call,all  subevent:begin  channel:local/0267@from-queue-2962;2  DESTINATION:SIP/601-00001BCA  calleridnum:07016317212  calleridname:rc07016317212  ConnectedLineNum: 0267  connectedlinename:0267  uniqueid:1339380988.50590  destuniqueid:1339380988.50591  dialstring:601 ";p Reg_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

Workaround:

Method One

PHP code

$tt = "Event:dial  privilege:call,all  subevent:begin  channel:local/0267@from-queue-2962;2  DESTINATION:SIP/601-00001BCA  calleridnum: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);

Method Two

PHP code

[User:root time:13:15:35 path:/home/liangdong/php]$ cat preg.php <?php$str = "Event:dial privilege:call,all SubEven T:begin channel:local/0267@from-queue-2962;2 DESTINATION:SIP/601-00001BCA calleridnum:07016317212 CALLERIDNAME:RC  07016317212 connectedlinenum:0267 connectedlinename:0267 uniqueid:1339380988.50590 destuniqueid:1339380988.50591 dialstring:601 "; $nmatches = Preg_match_all ('/(calleridnum| calleridname| connectedlinenum| connectedlinename| uniqueid| destuniqueid| dialstring): (s+)/', $STR, $matches);p Rint_r ($matches);? >[user:root time:13:15:36 path:/home/liangdong/php]$ php preg.php Array ([0] = = Array ([0] =&G T            calleridnum:07016317212 [1] = calleridname:rc07016317212 [2] = connectedlinenum:0267 [3] = connectedlinename:0267 [4] = uniqueid:1339380988.50590 [5] = = Destuniqueid : 1339380988.50591 [6] = dialstring:601) [1] = ArRay ([0] = calleridnum [1] = calleridname [2] = Connectedlinenum [3] = = Connectedlinename [4] = UniqueID [5] = Destuniqueid [6] = = Di            alstring) [2] = = Array ([0] = 07016317212 [1] = = rc07016317212            [2] = = 0267 [3] = 0267 [4] = 1339380988.50590 [5] = 1339380988.50591 [6] = 601))

Method Three

Change my s+ to s*.

The above is the PHP preg_mahch character interception solution idea content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.