Matt Elhotiby
Matt Elhotiby

Reputation: 44066

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. 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

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

)

Upvotes: 0

Views: 3791

Answers (1)

Sujit Agarwal
Sujit Agarwal

Reputation: 12508

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.

Upvotes: 2

Related Questions