|
In previous examples we have shown how easy it is to display XML feeds , sure there are plenty of moreover examples out there but there are plenty of other XML feeds available , in this example we choose a random news feed from 3 . The choices being spacetoday , osnews and versiontracker.
<?php
$urls = array("http://www.spacetoday.net/summaries.rdf",
"http://www.osnews.com/files/recent.rdf ",
"http://www.newsisfree.com/HPE/xml/feeds/80/3180.xml");
//generate a random number
srand(time());
$random = (rand()%3);
//get random feed
$random_feed = $urls[$random];
$xmlfile = fopen($random_feed, "r");
if(!$xmlfile)
die("cannot open the site");
$readfile = fread($xmlfile ,40000);
$searchfile = eregi("<item>(.*)</item>", $readfile ,$arrayreg);
$chunks = explode("<item>", $arrayreg[0]);
$count = count($chunks);
for($i=1 ; $i<=$count-1 ;$i++)
{
ereg("<title>(.*)</title>",$chunks[$i], $title);
ereg("<link>(.*)</link>",$chunks[$i], $links);
echo "<li>";
echo "<a href ='$links[1]'\>$title[1]</a>";
echo "</li>";
}
?>
|