我的一些客户想要将谷歌再营销代码添加到他们的网站,并且有一个面板可以做到这一点。
我strip_tags
用来从代码中删除不必要的标签(安全原因),但该函数也删除了CDATA
.
我怎样才能排除它?
示例再营销代码:
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 123456789;
var google_conversion_label = "AAAAAAAAAAAAAAAAAAA";
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/123456789/?label=AAAAAAAAAAAAAAAAAAA&guid=ON&script=0"/>
</div>
</noscript>
PHP代码:
$userContent = addslashes(strip_tags($data["analytics_code"],'<script><noscript><img><div>'));
输出是这样的:
<script type="text/javascript">
/* */
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/123456789/?label=AAAAAAAAAAAAAAAAAAA&guid=ON&script=0"/>
</div>
</noscript>
谢谢