Back To Normal
Click Here To Subscribe Via Email

Subscribe To Our E-Mail Newsletter

Saturday, October 25, 2014

How to Parse RSS Feeds in PHP

Couch ModePrint It


If you are building an app in PHP and you really want to parse and use RSS feeds in it like a PRO, then you wonder how to do that.

There are some RSS parsing libraries you can find. Using a good class or library will minimize your frustrations of managing and dealing with errors and debugging to get the perfect code.

These libraries can help you when you need to focus more on building your app's main functions instead of just running into further problems.

Well, i tried some good PHP RSS parsers but i liked Magpie RSS among all.

MagpieRSS provides an XML-based (expat) RSS parser in PHP.


MagpieRSS is an easy to use PHP RSS Parser. It has great features and it's hard to ignore its amazing parsing capabilities.

 MagpieRSS can parse

  • RSS 0.1 through RSS 1.0
  • RSS 1.0 (with modules)
  • RSS 2.0 
  • Atom




  • Easy to use
  • Parses RSS 0.9 - RSS 1.0
    Parses most RSS formats, including support for 1.0 modules and limited namespace support. RSS is packed into convenient data structures; easy to use in PHP, and appropriate for passing to a templating system, like Smarty.
  • Integrated Object Cache
    Caching the parsed RSS means that the 2nd request is fast, and that including the rss_fetch call in your PHP page won't destroy your performance, and force you to reply on an external cron job. And it happens transparently.
  • HTTP Conditional GETs
    Save bandwidth and speed up download times with intelligent use of Last-Modified and ETag.
    See HTTP Conditional Get for RSS Hackers
  • Configurable
    Makes extensive use of constants to allow overriding default behaviour, and installation on shared hosts.
  • Modular
    • - wraps a simple interface (fetch_rss()) around the library.
    • - provides the RSS parser, and the RSS object
    • - a simple (no GC) object cache, optimized for RSS objects
    • - utility functions for working with RSS. currently provides parse_w3cdtf(), for parsing W3CDTF into epoch seconds.
  • Secure - supports HTTP authentication, and SSL
  • Bandwidth friendly - supports transparent GZIP encoding to reduce bandwidth usage
  • Does not use fopen(), work even if allow_url_fopen is disabled.


 How to Use 


The usage is very simple and friendly. First of all, you know, include MagpieRSS file and then start using it to parse RSS feeds :)

/* include rss parser */

/* our rss feed url */

/* fetch the feed */
$rss = fetch_rss($url);

/* output what we got */
echo "<b>RSS Title: ".$rss->channel['title']."</b>";

/* loop on items received */
foreach ($rss->items as $item ) {
 $title = $item['title'];
 $description = $item['description'];
 $url   = $item['link'];
 echo "<a href="$url">$title</a>";

You can read more about MagpieRSS by clicking here.

Share your thoughts on RSS feeds and parsing them :)