How to create RSS feed Reader app in PHP
Php 26-Oct-2016

How to create RSS feed Reader app in PHP

RSS ( Rich Site Summary ) is a technology used by millions of web users to keep track of their favorite websites, in other words make you easily informed about your favorite fields. In this tutorial I will show you how you can create your own application to keep track on your favorite websites. Its a very simple and basic tutorial for PHP Developers, I have created 3 tabs of my favorite websites lets have a look how to code.

Using this article you can make your own daily reading app where you can read latest articles by your favorite websites on one page no need to go to all the websites individually and check if something interesting or not. Free code download and script demo available.

Simple PHP code:

index.php

contains PHP code to get RSS feeds from different websites

<?php
$rss = simplexml_load_file('http://feeds.feedburner.com/PhpGang');
$feed1 = '<h3>'. $rss->channel->title . '</h3>';
foreach ($rss->channel->item as $item) {
   $feed1 .= '<h4><a href="'. $item->link .'">' . $item->title . "</a></h4>";

}
$rss = simplexml_load_file('http://feeds.feedburner.com/TechCrunch/');
$feed2 = '<h3>'. $rss->channel->title . '</h3>';
foreach ($rss->channel->item as $item) {
   $feed2 .= '<h4><a href="'. $item->link .'">' . $item->title . "</a></h4>";

}
$rss = simplexml_load_file('http://mashable.com/feed/');
$feed3 = '<h3>'. $rss->channel->title . '</h3>';
foreach ($rss->channel->item as $item) {
   $feed3 .= '<h4><a href="'. $item->link .'">' . $item->title . "</a></h4>";

}
?>

In this code we are showing only RSS title and item title with link there is no description and date you can add article pos date of RSS feed and a short description as well.

Code to Read RSS date.

$feed3 .= "<p>" . $item->pubDate . "</p>";

Add this code in above feed code and it will display publish date of article.

Code to Read RSS article description.

$feed3 .= "<p>" . $item->description . "</p>";

Add this code in above feed code and it will show description of article.

HTML Tabs markup.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>How to read RSS feed in PHP | PGPGang.com</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <script type="text/javascript" src="jquery-1.8.0.min.js"></script> 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
$(function() {
    $( "#tabs" ).tabs();
  });
</script>
  </head>
  <body>
    <h2>How to read RSS feed in PHP example.&nbsp;&nbsp;&nbsp;=> <a href="http://www.phpgang.com/">Home</a> | <a href="http://demo.phpgang.com/">More Demos</a></h2>

<div id="tabs" style="margin-left:auto;margin-right:auto;width:600px;">
  <ul>
    <li><a href="#tabs-1">PHPGang</a></li>
    <li><a href="#tabs-2">TechCrunch</a></li>
    <li><a href="#tabs-3">Mashable</a></li>

  </ul>                 
  <div id="tabs-1">
  <?php echo $feed1; ?>
  </div>
  <div id="tabs-2">
  <?php echo $feed2; ?>
  </div>
  <div id="tabs-3">
  <?php echo $feed3; ?>
  </div>
</div>
</body>
</html>

This markup show 3 tabs of websites with there article title.

I hope you like this tutorial please feel free to comments your suggestions and problems you faced in its integration.