-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;       
4

1 回答 1

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];

于 2012-07-16T11:18:53.040 回答