Get latest posts from multiple feeds

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
renieravin
Forum Newbie
Posts: 3
Joined: Tue Sep 04, 2007 12:20 am

Get latest posts from multiple feeds

Post 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! :)
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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.
renieravin
Forum Newbie
Posts: 3
Joined: Tue Sep 04, 2007 12:20 am

thanks

Post 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? :wink:
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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;
        */
 }
?>
renieravin
Forum Newbie
Posts: 3
Joined: Tue Sep 04, 2007 12:20 am

Cool

Post 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.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

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