Read Rss/Atom feed using php

Web feed is a data format used to provide updates for blog or website. Most common types of feed are Rss and Atom. In this article you will learn how to read these feeds using php.

As we know that feeds are generated by using XML, so generic way to parse it by using php5 simplexml_load_file function. But we have to write different functions to parse different types of feed and versions.
To do this in simple way there is a php class named SimplePie

Php code to read Rss/Atom feed using SimplePie

<?
  $url="http://www.toolspot.org/feed.rss";
  include_once('SimplePie/autoloader.php');
  $feed = new SimplePie();
  $feed->set_feed_url($url);
  $feed->enable_cache(false);
  $feed->set_output_encoding('Windows-1252');
  $feed->init();
  $SiteTitle= $feed->get_title();
  $SiteDesc=$feed->get_description();
  $itemCount=$feed->get_item_quantity();
  $items=$feed->get_items();
  foreach($items as $item)
  {
  $Url=$item->get_permalink();
  $Title=$item->get_title();
  $Desc=$item->get_description();
  $Date=$item->get_date();
  if ($category = $item->get_category())
  $CatName = $category->get_label();
  }
  ?>
download zip Demo Download

Published on March 17, 2013 by Sunny Verma

Liked It? Get Free updates in your Email

Delivered by feedburner

comments powered by Disqus