【问题标题】:Get last urls from rss feeds with PHP使用 PHP 从 rss 提要中获取最后一个 url
【发布时间】:2014-07-24 11:27:31
【问题描述】:

想象我有一个来自网站的 RSS 提要,其中包含该网站的最新消息,

像这样:

http://example.com/feed

现在,我想从这个提要地址获取最新的新闻网址。

像这样:

http://example.com/post/555.php
http://example.com/post/554.php
http://example.com/post/553.php
http://example.com/post/552.php
http://example.com/post/551.php
http://example.com/post/550.php

如何在 PHP 中获取限制为(例如)25 个 url 的 url 列表?

【问题讨论】:

标签: php rss feed


【解决方案1】:

可以使用以下代码完成:

$rss = new DOMDocument();
$rss->load('http://wordpress.org/news/feed/');
$feed = array();

foreach ($rss->getElementsByTagName('item') as $node) {
    $item = array (
        'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
    );
    array_push($feed, $item);
}

$limit = 5;

for($x=0;$x<$limit;$x++) {
    echo $link = $feed[$x]['link'];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    相关资源
    最近更新 更多