Elliot Haughin

I'm a freelance web developer.
I build clever, engaging, ass-kicking,
web applications. You want me?

email me, tweet me, skype me

SimplePieParsing RSS feeds with PHP has always been a bit of a pain the ass.
But, SimplePie makes it much simpler!

In your controllers, simply load the library, set your feed url.. and you’re away!

$this->load->library('simplepie');
$this->simplepie->set_feed_url('http://feeds.haughin.com/haughin');
$this->simplepie->set_cache_location(APPPATH.'cache/rss');
$this->simplepie->init();
$this->simplepie->handle_content_type();
 
$data['rss_items'] = $this->simplepie->get_items();

Then, to use the feed data:

echo "<li>";
foreach($rss_items as $item) {
	echo "<li>";
	echo "<a href='" .$item->get_link() . "'>";
	echo $item->get_title();
	echo "</a>";
	echo "</li>";
}
echo "</li>";

You can pretty much use the data how you like… check out the simplepie documentation to see all of the data you can get from a feed.

Download Simplepie CodeIgniter Library

Version: 1.0

Sponsored Links

Comments

  1. [...] Elliot Haughin | SimplePie CodeIgniter Library Code Igniter com XML (tags: codeigniter library php rss simplepie) [...]

  2. [...] Elliot Haughin | SimplePie CodeIgniter Library (tags: codeigniter simplepie rss) [...]

  3. [...] within the already powerful CI environment. If interested, head over to Elliots website and download the code. Posted in CodeIgniter at July 1st, 2008. Trackback URI: [...]

  4. Jefferson Rafael says:

    very very good…..

  5. Mark Perkins says:

    Elliot, thanks for the port, I use it all the time.

    Just a minor point – in the second part of the code example (’Then, to use the feed data…’) I think the first and last lines of code should have ‘ul’ instead of ‘li’ in there.

    Thanks again for all your work on CI libs!

  6. Khoa says:

    I know SimplePie, and i had test code. Currently I only get the title and description, I’d like to get all of the contents show up.Please help me!.

  7. Benoa says:

    Hi Elliot,

    Thanks for the great classes you provide around here. That’s a real plus for the CI community.

    Here I don’t get what code did you add to SimplePie, as I thought I’d be able to use it “as is”? Could you explain to me please?

    Good luck with BinaryCake =)

Leave a Comment

© Copyright 2009 Elliot Haughin