0

我正在尝试在 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>&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>
4

1 回答 1

0

您遇到问题的原因是您不能在 RSS 提要中包含内联或外部的 JavaScript。

AdSense for RSS 可能依赖于第三方,但它的工作原理是在提要中包含图像或图像映射,而不是使用 JavaScript。

于 2009-08-19T12:37:52.807 回答