Display RSS From Other Websites

by Hiroshi on September 28, 2008

in RSS Parsing

Many popular websites provide their RSS links. i.e.

MSN Money Finance Tips
https://articles.moneycentral.msn.com/Feeds/RSS/financerss.aspx

MSN CNBC TV Updates
https://articles.moneycentral.msn.com/Feeds/RSS/cnbcrss.aspx

Technology and Science
https://rss.msnbc.msn.com/id/3032117/device/rss/rss.xml

Visit this URL to get a better idea.
https://rss.msn.com

You can get these URLS and display updates from these websites at your website in HTML user friendly readable format. wow!!!

For that you need xmlParser.

Suppose if you want to display content from following URL:

https://www.msn.com/rss/MsnEntertainment.aspx

You will need html page, containing script to call a PHP file which process both RSS URL and xml parser.

For example:

Put this script anywhere in the page where you want RSS to be displayed.

<script type="text/javascript" src="MsnEntertaintmentRss.php"></script>

Create a PHP page named as MsnEntertaintmentRss.php and put this code in.

document.write('<table border="0" cellspacing="0" cellpadding="0" width="100%">');
document.write('  <tr>');
document.write('    <td width="100%">');
<?php
require_once("xmlParser.php");
$sFeedUrl = "https://www.msn.com/rss/MsnEntertainment.aspx";
	$sXmlData = @file_get_contents($sFeedUrl);
	$xml = new XMLParser($sXmlData);
	$xml->Parse( );
	foreach ($xml->document->channel[0]->item as $item)
	{
		$title       = $item->title[0]->tagData;
		$link        = $item->link[0]->tagData;
		$pubDate     = $item->pubdate[0]->tagData;
		$description = $item->description[0]->tagData;
		$description = str_replace('src="', 'src="https://www.msn.com/', $description);
		$description = str_replace('../', '', $description);
		$description = addslashes($description);
		$description = str_replace('</a>', '</a> ', $description);
		$description = str_replace('<a', ' <a', $description);
		print "document.write('<a href=\"".$link."\" target=\"_blank\" class=\"news\">".addslashes($title)."</a><br>');\n";
		print "document.write('<i>".$pubDate."</i><br><br style=\"line-height:8px;\">');\n";
		print "document.write('".$description."<br><br>');\n";
	}
?>
document.write('    </td>');
document.write('  </tr>');
document.write('</table>');

Place xmlParser.php with the two files and browse your HTML page containing script. You will need to upload these files to online server or test these in wamp (locaclhost).

Download all files including xmlParser.php below

Download xmlparser Example for Feeds

Related Posts

Previous post:

Next post: