2012-07-16 28 views
-2

我有爬的丁文和營銷代碼的腳本,但我需要檢測的轉換ID, 防爆幫助:需要幫助的正則表達式檢測谷歌轉換編號

<!-- Google Code for current client Remarketing List --> 
<script type="text/javascript"> 
/* <![CDATA[ */ 
var google_conversion_id = 1057577648; 
var google_conversion_language = "en"; 
var google_conversion_format = "3"; 
var google_conversion_color = "666666"; 
var google_conversion_label = "FJ8sCKCE9wEQsLWl-AM"; 
var google_conversion_value = 0; 
/* ]]> */ 

極品的正則表達式是這樣的:

$gaRegExp = "Regex Here"; 

preg_match($gaRegExp , $str , $matches); 

$conversion_id = $matches;  

回答

0

試試這個

$subject = 'var google_conversion_id = 1057577648; 
var google_conversion_language = "en"; 
var google_conversion_format = "3"; 
var google_conversion_color = "666666"; 
var google_conversion_label = "FJ8sCKCE9wEQsLWl-AM"; 
var google_conversion_value = 0;'; 
$pattern = '!(?<=google_conversion_id\s\=\s)\d+!'; 
preg_match($pattern, $subject, $matches); 
print_r($matches); 

輸出:

Array ([0] => 1057577648) 

爲了獲得元素$conversion_id=$matches[0];

+0

感謝阿列克謝會嘗試它,我真的很感激你的幫助 – user1528706 2012-07-16 11:24:48