需要在regex中帮助检测谷歌转换ID



我有一个脚本可以抓取覆盖和重新标记代码,但我需要帮助检测转换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;       

试试这个

$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_ids=s)d+!';
preg_match($pattern, $subject, $matches);
print_r($matches);

输出:

Array ( [0] => 1057577648 ) 

获取元素$conversion_id=$matches[0];

相关内容

  • 没有找到相关文章

最新更新