Parsing 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