Page 1 of 1
Get latest posts from multiple feeds
Posted: Tue Sep 04, 2007 12:34 am
by renieravin
Need some help - badly! I have a directory of bloggers, where I store the RSS feed url's of their blogs in a MySQL db. (There are about 1000 blogs so far) How do I go about displaying the latest posts from these feeds on a page?
Thanks in advance!

Posted: Tue Sep 04, 2007 11:11 am
by anjanesh
Use some XML functions like
DOM XML,
DOM or
SimpleXML to read, parse & calculate.
For a task like this it may be time consuming for the script's execution. Try storing the feeds' items (except the post boy itself) into the database acting as a cache. And setup a cron to do the updates or something.
thanks
Posted: Wed Sep 05, 2007 12:06 am
by renieravin
Thanks Anjanesh, the problem is - I have no idea how to do that, although I was wary of having to deal with script timeouts, etc. Basically I can even run a script every few hours which would update the db with the latest posts across all feeds...
Is there any more info you can give me? Is there a ready made script available that I can modify and use?

Posted: Wed Sep 05, 2007 12:22 am
by anjanesh
Its just too easy with PHP5's SimpleXML - if you're still on PHP4, seriously consider moving to PHP5 - it'll save a lot of time.
Code: Select all
<?php
$xml = simplexml_load_file("http://rss.anjanesh.net/anjanesh");
foreach($xml->channel->item as $item)
{
echo $item->pubDate.', '.$item->title."<br/>\n";
/*
echo $item->link;
print_r($item->category);
echo $item->description;
*/
}
?>
Cool
Posted: Wed Sep 05, 2007 12:38 am
by renieravin
Thanks a ton man. I have root access to my server, so I had installed PHP 5 on it. Will try out this code soon and let you know if it works.
Posted: Wed Sep 05, 2007 12:53 am
by anjanesh
Also note, even though PHP 5 versions are more-or-less the same, there are couple of differences between PHP 5.0.x, PHP 5.1.x and PHP 5.2.x.
For example, you dont need to escape urls from PHP 5.1.0 for simplexml_load_file contructor. But prior to PHP 5.1.0, you may need to.
So I suggest using PHP 5.2.x (PHP 5.2.4 as of today) since you got root access.