RSS Feed Example using Ajax & PHP


Really Simple Syndication (RSS) is used to publish often updated information from website like audio, video, images, etc. RSS is a technology that is being used by millions of web users around the world to keep track of their favorite websites.

Why RSS ? 

RSS solves a problem for people who regularly use the web. It allows you to easily stay informedby retrieving the latest content from the sites you are interested in. You save time by not needing to visit each site individually. You ensure your privacy, by not needing to join each site’s email newsletter.

We can integrate RSS feeds to a website by using Ajax and php. This blog will  demonstrates how to show RSS feeds in our site.

Let us say we are having RSS folder in Htdocs folder (as i am using xampp for demonstrating). So Create one file in RSS folder named “index.html”, which content a selection box with 3 options (CNN, BBC News, PC world).


Index page should be as follows −

         function showRSS(str) {
            if (str.length==0) { 
            if (window.XMLHttpRequest) {
               xmlhttp=new XMLHttpRequest();
               xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            xmlhttp.onreadystatechange=function() {
               if (xmlhttp.readyState==4 && xmlhttp.status==200) {
      <p>Please Select an option to get RSS:</p>
         <select onchange="showRSS(this.value)">
            <option value="">Select an RSS-feed:</option>
            <option value="cnn">CNN</option>
            <option value="bbc">BBC News</option>
            <option value="pc">PC World</option>
</body> </html>


rss.php has contained syntax about how to get access to rss feeds and return rss feeds to web pages.

   if($q=="cnn") {
   elseif($q=="bbc") {
   $xmlDoc = new DOMDocument();
   $channel_title = $channel->getElementsByTagName('title')
   $channel_link = $channel->getElementsByTagName('link')
   $channel_desc = $channel->getElementsByTagName('description')
   echo("<p><a href='" . $channel_link . "'>" . $channel_title . "</a>");
   echo($channel_desc . "</p>");
   for ($i=0; $i<=2; $i++) {
      echo ("<p><a href='" . $item_link . "'>" . $item_title . "</a>");
      echo ("<br>");
      echo ($item_desc . "</p>");

Download Code

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s