简体   繁体   English

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

[英]how do i get the content for the last rss feed

I have this feed and i just need to parse out the latest rss feed.我有这个提要,我只需要解析出最新的 rss 提要。 I basically want to know if i can get the information for the latest one...I have this code that helps parse all the rss feeds but how do i just get the latest我基本上想知道我是否可以获得最新的信息...我有这段代码可以帮助解析所有 rss 提要,但我如何才能获得最新的

$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));
}

EDIT: tried编辑:试过

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

but the description is blank但描述是空白的

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
        (
        )

)

Answer edited:答案编辑:

<pre>
<?php

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

This is the sample where i am reading the latest post.这是我正在阅读最新帖子的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM