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)!