Light Weight RSS Reader With PHP

From last two days my brain is empty. I was not getting any new ideas for my blog post. After I jumped into my previous projects I found XML reader with PHP project. I did that  1 year back(approx). So I decided to convert that into Simple Light Weight RSS Reader(of-course RSS also a XML!). Now here it is! Have a look at the demo below before start.
Light Weight RSS Reader With PHP-Techumber.com


demo

download

Note: If who want to test the demo or downloaded script. Please Make sure your feeds are RSS format not atom format. If it is atom It won't work in this tutorial.
You can simply convert feed format form atom to rss in your feedburner settings if you use feedburner for your feeds.

The is very simple. Here we will have only one file.
--index.php Form(HTML-Code)

<div class="span5 offset3 mini-layout">  
<h2>Enter feed url!</h2>  
<p class="alert alert-info">Ex:http://feeds.feedburner.com/techumber</p>  
<form action="" method="get">  
<input class="span5" type="text" id="feedurl" name="feedurl" value="http://feeds.feedburner.com/techumber">  
<button type="submit" class="btn btn-info ">Submit</button>  
</form>  
</div> 

This is the simple form. Here you can enter your feed url.
Result display Code

<?php  
//displaying the result 
if($displayrss)  
{ 
echo $displayrss;  
} 
?> 

In this code first it will check if any value in $displayrss variable. If yes then it will display the result.
Main script

<?php  
$feedurl=""; 
$displayrss=""; 
if(!empty($_GET["feedurl"]))  
{ 
$feedurl=stripcslashes($_GET["feedurl"]); 
} 
else  
{ 
$feedurl='http://feeds.feedburner.com/techumber'; 
} 
//Loading the rss xml file 
$rssxml = simplexml_load_file($feedurl); 
//We generating list iteams to display later on the same page 
$displayrss='<ul class="nav nav-tabs nav-stacked">'; 
//listing all iteams in to <li> list with there posttitle and postlink 
foreach ($rssxml->channel->item as $item) {  
//Post Title 
$ptitle = (string) $item->title; 
//post link 
$plink = (string) $item->link; 
$displayrss.= 
'<li>  
<a href="'.$plink.'" target="_blank" title="" >'.$ptitle.' </a>  
</li>';  
} 
$displayrss.="</ul>"; 

In this code first we check if user entered any feed url. If not we will assign default url http://feeds.feedburner.com/techumber (This is techumber feed url). You can change it if you want.
We use PHP function simplexmlloadfile to convert the xml into objects. After that we used  foreach to loop through all the nodes and we generated a HTML code which we assigned to $displayrss variable. We used this varible in Result Display Code
That's it!
If you like my posts Please share it with you friends and help them learn new thing. Thank You!:D

Get posts by email

Like what you're reading? Get these posts delivered to your inbox.