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>&lt;a href=&quot;http://www.domain.com/image-8551.html&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://www.domain.com/images/1250670754.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I guess being called snuggly-bumpkins was too much?&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
                    google_ad_client = &quot;pub-3790901073xxxxx&quot;;
                    /* banner, RSS Feed */
                    google_ad_slot = &quot;xxxxxxx&quot;;
                    google_ad_width = 468;
                    google_ad_height = 60;
                    //--&gt;

                    &lt;/script&gt;
                    &lt;script type=&quot;text/javascript&quot;
                    src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
                    &lt;/script&gt;&lt;p&gt;&lt;a href=&quot;http://www.domain.com/image-8551.html&quot; target=&quot;_blank&quot;&gt;Post a comment &gt;&lt;/a&gt;</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流