RSS 流中的 AdSense - PHP
我正在尝试在 RSS 流中添加一些 Google AdSense。 我不想使用他们的“AdSense for RSS”,因为它依赖于第三方。
我注意到在 RSS 中,您不能使用小于/大于字符,因为它会破坏 RSS 代码。 好吧,我使用 htmlentities() 函数来转义这些。 它可以很好地在流中显示基本的 HTTP,如下所示:
$bottom = '<p><a href="http://www.domain.com/image-' .$row['id']. '.html" target="_blank">Post a comment ></a>';
echo htmlentities($bottom);
但是,当我尝试使用 Google AdSense 代码执行完全相同的操作时,没有任何显示。
$ad_code = '<script type="text/javascript"><!--
google_ad_client = "pub-37909010735xxxx";
/* banner, RSS Feed */
google_ad_slot = "xxxxx";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
echo htmlentities($ad_code);
起初我以为 Google 阻止了 AdSense 的使用,以强制用户使用 AdSense for RSS 服务,但后来我注意到一些流行网站(例如 Slashdot)所做的正是我想做的。
我肯定做错了什么,但我无法指责它。
编辑:这是输出
<description><a href="http://www.domain.com/image-8551.html" target="_blank"><img src="http://www.domain.com/images/1250670754.jpg" /></a><br /><br />I guess being called snuggly-bumpkins was too much?<script type="text/javascript"><!--
google_ad_client = "pub-3790901073xxxxx";
/* banner, RSS Feed */
google_ad_slot = "xxxxxxx";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><p><a href="http://www.domain.com/image-8551.html" target="_blank">Post a comment ></a></description>
I'm trying to add some Google AdSense in a RSS stream. I don't want to use their "AdSense for RSS" because it relies on a third-party.
I noticed that in RSS, you cannot use the lesser/greater than characters because it breaks the RSS code. Fine, I use the htmlentities() function to escape those. It works fine to display basic HTTP in the stream, like so:
$bottom = '<p><a href="http://www.domain.com/image-' .$row['id']. '.html" target="_blank">Post a comment ></a>';
echo htmlentities($bottom);
However when I try to do the exact same thing with the Google AdSense code, nothing shows.
$ad_code = '<script type="text/javascript"><!--
google_ad_client = "pub-37909010735xxxx";
/* banner, RSS Feed */
google_ad_slot = "xxxxx";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
echo htmlentities($ad_code);
At first I thought Google blocked that use of AdSense, to force users to the AdSense for RSS service, but then I noticed that some popular websites such as Slashdot do exactly what I want to do.
Surely I'm doing something wrong but I can't put the finger on it.
Edit: This is the output
<description><a href="http://www.domain.com/image-8551.html" target="_blank"><img src="http://www.domain.com/images/1250670754.jpg" /></a><br /><br />I guess being called snuggly-bumpkins was too much?<script type="text/javascript"><!--
google_ad_client = "pub-3790901073xxxxx";
/* banner, RSS Feed */
google_ad_slot = "xxxxxxx";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><p><a href="http://www.domain.com/image-8551.html" target="_blank">Post a comment ></a></description>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您遇到问题的原因是您无法在 RSS 提要中包含内联或外部的 JavaScript。
AdSense for RSS 可能依赖于第三方,但它的工作原理是在 Feed 中包含图像或图像映射,而不是使用 JavaScript。
The reason you're having trouble is that you can't include JavaScript, inline or external, inside RSS feeds.
AdSense for RSS might rely on a third-party, but it works by including an image, or an image map, into the feed and not by using JavaScript.