Location: PHPKode > scripts > PHP AJAX RSS News Reader > php-ajax-rss-news-reader/classes/class.rssnews.php
<?php
/**
 * class.rssnews.php
 * The RSS Feeds retrieving class
 * 
 * created by Nitesh Apte
 * License: GNU Public License 
 */
class  rssnews
{	
	private $rss;
	private $items;
	private $item;
	private $title;
	private $link;
	
	/**
	 * __construct
	 * This function retrieve the xml feed and displays it.
	 *
	 */
	function __construct($url)
	{
		if($url=="google")	
		$this->url = "http://news.google.co.in/nwshp?hl=en&tab=wn&output=rss";
		if($url=="bbc")	
		$this->url = "http://newsrss.bbc.co.uk/rss/newsonline_world_edition/asia-pacific/rss.xml";
		if($url=="reuters")	
		$this->url = "http://feeds.reuters.com/reuters/worldNews";
		if($url=="rediff")	
		$this->url = "http://www.rediff.com/rss/inrss.xml";
		if($url=="toi")	
		$this->url = "http://timesofindia.indiatimes.com/rssfeedsdefault.cms";
		if($url=="hindu")	
		$this->url = "http://www.hindu.com/rss/01hdline.xml";
		if($url=="pk")
		$this->url ="http://www.prabhatkhabar.com/rssfeedback.aspx?pageno=2";
		if($url=="et")
		$this->url = "http://economictimes.indiatimes.com/rssfeedsdefault.cms";
		
		$this->rss = simplexml_load_file($this->url);
		if($this->rss)
		{	
			$this->items = $this->rss->channel->item;
			foreach($this->items as $this->item)
			{
				$this->title = $this->item->title;
				$this->link = $this->item->link;
				echo '<a href="'.$this->link.'" target="_blank">'.$this->title.'</a><br/>';
			}
		}
		else 
		echo "Unable to parse XML";
	}
}
?>
Return current item: PHP AJAX RSS News Reader