我如何获取最后一个RSS Feed的内容

时间:2011-05-30 15:24:57

标签: php rss feed

我有这个feed,我只需要解析最新的RSS Feed。我基本上想知道我是否能获得最新的信息...我有这个代码可以帮助解析所有的rss feed但我如何才能得到最新的

$validCache = false;
if (file_exists('rss_cache.txt')) {
    $contents = file_get_contents('rss_cache.txt');
    $data = unserialize($contents);
    if (time() - $data['created'] < 24 * 60 * 60) {
        $validCache = true;
        $feed = $data['feed'];
    }
}

if (!$validCache) {
    $feed = file_get_contents('http://someplace.com/feed/');
    $data = array ('feed' => $feed, 'time' => time());
    file_put_contents('rss_cache.txt', serialize($data));
}

编辑:试过

$xml = simplexml_load_file('http://blog.airdye.com/goodforwater/feed/');
print_r($xml->channel->item[0]);

但描述为空白

SimpleXMLElement Object
(
    [title] => one textile company gives away water filters and profits
    [link] => http://blog.airdye.com/goodforwater/2011/05/20/one-textile-company-gives-away-water-filters-and-profits/
    [comments] => http://blog.airdye.com/goodforwater/2011/05/20/one-textile-company-gives-away-water-filters-and-profits/#comments
    [pubDate] => Fri, 20 May 2011 20:09:31 +0000
    [category] => Array
        (
            [0] => SimpleXMLElement Object
                (
                )

            [1] => SimpleXMLElement Object
                (
                )

            [2] => SimpleXMLElement Object
                (
                )

            [3] => SimpleXMLElement Object
                (
                )

            [4] => SimpleXMLElement Object
                (
                )

        )

    [guid] => http://blog.airdye.com/goodforwater/?p=2673
    [description] => SimpleXMLElement Object
        (
        )

)

1 个答案:

答案 0 :(得分:2)

回答编辑:

<pre>
<?php

$xml = simplexml_load_file('http://wizardsoweb.com/feed');
print_r($xml->channel->item[0]);
?>
</pre>

这是我正在阅读最新帖子的示例。