Light Weight RSS Reader With PHP

Github avatar
September 19, 2012. 2 min read

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



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://</p>
<form action="" method="get">
<input class="span5" type="text" id="feedurl" name="feedurl" value="//">
<button type="submit" class="btn btn-info ">Submit</button>

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

//displaying the result
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

//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;
<a href="'.$plink.'" target="_blank" title="" >'.$ptitle.' </a>

In this code first we check if user entered any feed url. If not we will assign default url // (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