PHP Tutorial
Advanced PHP
PHP Form Examples
PHP login Examples
PHP AJAX Examples
PHP XML Example
PHP Frame Works
PHP Design Patterns
PHP Function Reference
PHP Useful Resources
Selected Reading
- PHP - Coding Standard
- PHP - File Uploading
- PHP - Sending Emails
- PHP - Sessions
- PHP - Cookies
- PHP - Functions
- PHP - Files & I/O
- PHP - File Inclusion
- PHP - GET & POST
- PHP - Web Concepts
- PHP - Strings
- PHP - Arrays
- PHP - Loop Types
- PHP - Decision Making
- PHP - Operator Types
- PHP - Constants
- PHP - Variable Types
- PHP - Syntax Overview
- PHP - Environment Setup
- PHP - Introduction
- PHP - Home
Advanced PHP
- PHP - For PERL Developers
- PHP - For C Developers
- PHP - Object Oriented
- PHP & XML
- PHP & AJAX
- PHP & MySQL
- PHP - Date & Time
- PHP - Bugs Debugging
- PHP - Error Handling
- PHP - Regular Expression
- PHP - Predefined Variables
PHP Form Examples
PHP login Examples
PHP AJAX Examples
PHP XML Example
- PHP - DOM Parser Example
- PHP - SAX Parser Example
- PHP - Simple XML GET
- PHP - Simple XML
- PHP - XML Introduction
PHP Frame Works
PHP Design Patterns
PHP Function Reference
PHP Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PHP - AJAX RSS Feed Example
PHP - Ajax RSS Feed Example
RSS
Really Simple Syndication is used to pubpsh often updated information from website pke audio, video, images, etc. We can integrate RSS feeds to a website by using Ajax and php. This code demonstrates how to show RSS feeds in our site.
Index.html
Index page should be as follows −
<html> <head> <script> function showRSS(str) { if (str.length == 0) { document.getElementById("output").innerHTML = ""; return; } if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); }else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("output").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET","rss.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <p>Please Select an option to get RSS:</p> <form> <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> </select> </form> <br> <span id = "output">RSS-feeds</span> </body> </html>
rss.php
rss.php has contained syntax about how to get access to rss feeds and return rss feeds to web pages.
<?php $q = $_GET["q"]; if($q == "cnn") { $xml = ("http://rss.cnn.com/rss/cnn_topstories.rss"); }elseif($q == "bbc") { $xml = ("http://newsrss.bbc.co.uk/rss/newsonpne_world_edition/americas/rss.xml"); }elseif($q = "pcw"){ $xml = ("http://www.pcworld.com/index.rss"); } $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); $channel = $xmlDoc->getElementsByTagName( channel )->item(0); $channel_title = $channel->getElementsByTagName( title ) ->item(0)->childNodes->item(0)->nodeValue; $channel_pnk = $channel->getElementsByTagName( pnk ) ->item(0)->childNodes->item(0)->nodeValue; $channel_desc = $channel->getElementsByTagName( description ) ->item(0)->childNodes->item(0)->nodeValue; echo("<p><a href = " . $channel_pnk . " >" . $channel_title . "</a>"); echo("<br>"); echo($channel_desc . "</p>"); $x = $xmlDoc->getElementsByTagName( item ); for ($i = 0; $i<=2; $i++) { $item_title = $x->item($i)->getElementsByTagName( title ) ->item(0)->childNodes->item(0)->nodeValue; $item_pnk = $x->item($i)->getElementsByTagName( pnk ) ->item(0)->childNodes->item(0)->nodeValue; $item_desc = $x->item($i)->getElementsByTagName( description ) ->item(0)->childNodes->item(0)->nodeValue; echo ("<p><a href = " . $item_pnk . " >" . $item_title . "</a>"); echo ("<br>"); echo ($item_desc . "</p>"); } ?>
It will produce the following result −
Advertisements