2014-02-09 31 views

回答

0
$string = "David Smith (Local/[email protected]/n from SIP/202) (ringinuse enabled) (Not in use) has taken 1 calls (last was 843 secs ago)"; 
$result= array(); 
preg_match("/taken\s(\d+)/", $string, $result); 

var_dump($result); 

結果:

array(2) { 
      [0]=> string(7) "taken 1" 
      [1]=> string(1) "1" // this is your number 
} 

編輯:現在,這個數字可能會超過1個位數

+0

謝謝,那有效。 – user3148002

+0

如果數字超過1,preg_match是多少,有時數字可能是2位數字或3位數字。此刻如果數字是12,我只在數組字符串中獲得1。 – user3148002

+0

嗯..是的,你是對的,我會編輯它:) – demonking

0

使用正則表達式:

<?php 
$string = "David Smith (Local/[email protected]/n from SIP/202) (ringinuse enabled) (Not in use) has taken 1 calls (last was 843 secs ago)"; 
$matches = array(); 

if (1 === preg_match('/taken (\d+) calls/', $string, $matches)) { 
    echo $matches[1]; 
} 
相關問題