Re: AJAX RSS Reader in PHP
An RSS Reader is used to read RSS Feeds. That means the user can give the feed back about your webpage. For that purpose the RSS Feeds are used so that you can get an idea accordingly. An RSS document includes full or summarized text, plus metadata such as publishing dates. A standardized XML file format allows the information to be published once and viewed by many different programs. As said before that the user subscribes to a feed by entering into the reader the feed's URI or by clicking an RSS icon in a web browser that initiates the subscription process.
Re: AJAX RSS Reader in PHP
RSS formats are specified using XML, a generic specification for the creation of data formats. You may insert one RSS feed which is having many different versions of it. The specification is an independent draft not supported or endorsed in any way by the RSS-Dev Working Group or any other organization. The most serious compatibility problem is with HTML markup. In order to be usable by other parties, the data to be shared must be in a generic format that can be laid out in different formats than in the original source.
Re: AJAX RSS Reader in PHP
The HTML page contains a link to an external JavaScript, an HTML form, and a div element. The following code would be useful for you :
HTML Code:
<html>
<head>
<script type="demo/javascript" src="getrss.js"></script>
</head>
<body>
<form>
Select an RSS-feed:
<select onchange="showRSS(this.value)">
<option value="Google">Google News</option>
<option value="MSNBC">MSNBC News</option>
</select>
</form>
<p><div id="rssOutput">
<b>RSS-feed will be listed here...</b></div></p>
</body>
</html>
Re: AJAX RSS Reader in PHP
The PHP page called by the JavaScript code is called "getrss.php" :
PHP Code:
<?php
$q=$_GET["q"];
if($q=="Google")
{
$xml=("http://news.google.com/news?ned=us&topic=h&output=rss");
}
elseif($q=="MSNBC")
{
$xml=("http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml");
}
$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
$channel_title = $channel->getElementsByTagName('title')
->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName('link')
->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $channel->getElementsByTagName('description')
->item(0)->childNodes->item(0)->nodeValue;
echo("<p><a href='" . $channel_link
. "'>" . $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_link=$x->item($i)->getElementsByTagName('link')
->item(0)->childNodes->item(0)->nodeValue;
$item_desc=$x->item($i)->getElementsByTagName('description')
->item(0)->childNodes->item(0)->nodeValue;
echo ("<p><a href='" . $item_link
. "'>" . $item_title . "</a>");
echo ("<br />");
echo ($item_desc . "</p>");
}
?>