Class 10 – SimplePie: an RSS Parser Library for PHP

Posted: April 25th, 2009 | Author: | Filed under: php, rss | Tags: | No Comments »

In class today, we’re looking at an example of how you can use the SimplePie PHP library to pull content from any site’s RSS feed and display it on your own pages.

In this example, SimplePie is acting as the Model in an MVC architecture. index.php is the Controller, and index_view.php is the View.

In the example files, you will notice that there is a folder called “cache”. This is where SimplePie temporarily stores copies of the RSS feeds that you load. It keeps each cached copy of the RSS feed for several minutes, so that if you reload your page, it doesn’t have to always reload the same data from the site that publishes the RSS feed.

In fact, some sites will ban your site from accessing their RSS feeds forever unless you store cached copies of their feeds. This is because they want to minimize the number of requests that are made to their servers. SimplePie does this by default if you have a “cache” folder available.

You’ll also notice an “images” folder.  This stores default placeholder images for media files.  SimplePie integrates with the JW Media Player application.  So if a particular RSS feed has media attachments, whether audio or video, SimplePie will automatically generate the appropriate JW Media Player code, so you don’t have to worry about doing it yourself.

If you use SimplePie, you will need to make sure you have the simplepie.inc file (which holds the main SimplePie code), the cache folder (which stores cached copies of all RSS feeds), the images folder with default images, and the idn folder (which holds other misc SimplePie files).

No related posts.



Leave a Reply