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.

  1. 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 😉
  2. If you want to skip the demo the only file you actually need is simplepie.inc
  3. 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 = “

  4. Digitalpoint
  5. Favicon generator
  6. phpClasses.org
  7. R&OS PDF tool
  8. Wowexe.exe
  9. 9 Comments

    1. May 11, 2006

      Where is the CakePHP SimplePie snippet? I just can’t find it.

    2. May 12, 2006

      Why the tables? 🙁

    3. May 12, 2006

      In the example? That’s just a hangover from the original test. I’d use a list normally.

    4. May 17, 2006

      How do i echo getsimplepie?

    5. May 18, 2006

      just

      [php]echo getSimplePie(‘http://mysite.com/feed/’);[/php]

    6. obay
      June 21, 2007

      is there a way to include more than one rss feed?

    7. June 22, 2007

      No, but you can get several feeds – build them into an array, sort and output.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.