May 8, 2006
Using SimplePie to parse RSS
Cake PHP have launched a new version or their PHP framework and one of the snippets was the integration of SimplePie. The install and demo for normal sites is incredibly simple and the code is fully featured but held in a single file. It can even spit out the "subscribe via" links for the major sites.
All in all it appears to be very impressive.
- Unzip the files on your local file system and run the demo and make sure everything is setup ok. Don't be alarmed by the huge logo, you are still on your own site
- If you want to skip the demo the only file you actually need is simplepie.inc
- create this function in your script
PHP:
-
function getSimplePie($url)
-
{
-
include('simplepie/simplepie.inc');
-
// Parse it
-
$feed = new SimplePie();
-
$feed->feed_url($url);
-
$feed->cache_location('./../cache');
-
$feed->init();
-
-
if ($feed->data)
-
{
-
$output = "<table cellspacing='0' cellpadding='0'>
-
<tr><th valign='top'>
-
<a href=" . $feed->get_feed_link() . ">"
-
.$feed->get_feed_title()
-
."</a> - ".$feed->get_feed_description()
-
."</th></tr>";
-
-
for ($x = 0; $x <$max; $x++)
-
{
-
$output .= "<tr>
-
<td>
-
<a href='" . $feed->get_item_permalink($x) . "'>"
-
.$feed->get_item_title($x)
-
."</a>
-
</td>\n";
-
}
-
}
-
$output .= "</table>";
-
return $output;
-
}//getSimplePie
-
- You can now echo getSimplePie and pass in the feed address from anywhere in your page.



[...] SimplePie [...]
Pingback by Simple SEO » Adding RSS to your website — May 8, 2006 @ 2:47 pm
Where is the CakePHP SimplePie snippet? I just can’t find it.
Comment by Geoffrey Sneddon — May 11, 2006 @ 9:11 am
Hi Geoffrey, I picked it up here: http://cakeforge.org/snippet/detail.php?type=snippet&id=53
Comment by sarahk — May 11, 2006 @ 9:19 am
Why the tables?
Comment by EJ Fox — May 12, 2006 @ 9:13 am
In the example? That’s just a hangover from the original test. I’d use a list normally.
Comment by sarahk — May 12, 2006 @ 9:17 am
How do i echo getsimplepie?
Comment by Ashley — May 17, 2006 @ 11:37 pm
just
[php]echo getSimplePie(’http://mysite.com/feed/’);[/php]
Comment by Sarah King — May 18, 2006 @ 7:34 am
is there a way to include more than one rss feed?
Comment by obay — June 21, 2007 @ 8:55 pm
No, but you can get several feeds - build them into an array, sort and output.
Comment by Sarah King — June 22, 2007 @ 2:52 am