AdSense in RSS Stream
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>
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.
链接地址: http://www.djcxy.com/p/32364.html上一篇: AdWords中的标记和UTM变量?
下一篇: AdSense RSS流