SimplePie is a popular RSS parser and it was always easy to integrate it with other PHP frameworks.
However, I was not able to find the latest SP (1.2.1) integrated with the latest CI (2.1.0). So I decided to upload it to GitHub and make it available for all to use. The repo is available at
There are two things I did to make this work, which weren’t too difficult.
First is to ensure that SP references are correctly fixed up when porting to CI. This is well documented with links in
Secondly, when I was running this, it was giving the following error.
cURL error 6: name lookup timed out
It seemed like cURL was timing out when trying to access the remote RSS feed. The value for timeout is set to 10 seconds by default. Maybe this is a bit too strict. I changed this to 20 and it worked well.
Finally, here’s the snippet of my code to get this thing working. Make sure you include Simplepie.php in your libraries folder and also set your “cache” folder as writable.
public function aus_conf()
{
$this->load->library('Simplepie');
$this->simplepie->set_cache_location(APPPATH.'cache');
$this->simplepie->set_feed_url('http://feeds.feedburner.com/TheAustralianArt?format=xml');
$this->simplepie->init();
$this->simplepie->handle_content_type();
foreach( $this->simplepie->get_items(0, 5) as $item)
{
echo $item->get_title() . '
';
echo $item->get_description();
}
}
Excellent thanks for sharing saved me a bunch of work
No worries! Glad you found it useful!