解析RSS机箱URL - PHP

时间:2018-06-08 06:20:18

标签: php rss

所以我面临一个非常奇怪的情况,我试图从特定项目的RSS源解析机箱URL。我需要链接到图像附件。但是,我一直在尝试的所有方法都为我提供了图像链接的实际文章链接。

<item> <title>Patches of Snow on the Red Planet</title>
<link>http://www.nasa.gov/image-feature/patches-of-snow-on-the-red- 
planet</link>
<description>In early Martian summer, at the time NASA&#039;s Mars 
Reconnaissance Orbiter acquired this image, the dunes are almost free of 
their seasonal ice cover.</description>
<enclosure 
url="http://www.nasa.gov/sites/default/files/thumbnails/image/marssnow.jpg" 
length="516834" type="image/jpeg" />
<guid isPermaLink="false">http://www.nasa.gov/image-feature/patches-of-snow- 
on-the-red-planet</guid>
<pubDate>Tue, 05 Jun 2018 15:06 EDT</pubDate>
<source url="http://www.nasa.gov/rss/dyn/image_of_the_day.rss">NASA Image of 
the Day</source>
</item>

我已经尝试了各种各样的

$this->enclosure->url;

$this->enclosure['url'];

等。

即使我试图获得机箱长度,我仍然会收回文章网址。

我找回了&#34;链接&#34;网址而不是机箱网址。

任何帮助表示赞赏。先感谢您。

1 个答案:

答案 0 :(得分:0)

你应该使用 getAttribute('url')按标记名称获取DOM元素 之后使用enclosure<?php header('Content-Type: application/json'); $xml = <<< XML <item> <title>Patches of Snow on the Red Planet</title> <link>http://www.nasa.gov/image-feature/patches-of-snow-on-the-red- planet</link> <description>In early Martian summer, at the time NASA&#039;s Mars Reconnaissance Orbiter acquired this image, the dunes are almost free of their seasonal ice cover.</description> <enclosure url="http://www.nasa.gov/sites/default/files/thumbnails/image/marssnow.jpg" length="516834" type="image/jpeg" /> <guid isPermaLink="false">http://www.nasa.gov/image-feature/patches-of-snow- on-the-red-planet</guid> <pubDate>Tue, 05 Jun 2018 15:06 EDT</pubDate> <source url="http://www.nasa.gov/rss/dyn/image_of_the_day.rss">NASA Image of the Day</source> </item> XML; $dom = new DOMDocument; $dom->loadXML($xml); $ens = $dom->getElementsByTagName('enclosure'); foreach ($ens as $en) { echo $en->getAttribute('url'); } ?> 标记

获取网址

我的代码

(function($) {
    $(document).ready(function() {
        /
        $('.auto-scroll').off('click').on('click', function(event) {
            event.preventDefault();
            ....
            ....
        });

        $("#btnBuscar").on("click", function() {
            ...
            ...
        });
    });

})(jQuery);