Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

Make money selling software. Check this out here

Hosted clickbank mall. Check this out here




   Misc

   Amazon

   Links

    


Random XML feeds

 

 

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>";
}
?>

 

 


 

 

And here it is , refresh browser to see others


Warning: fopen() [function.fopen]: URL file-access is disabled in the server configuration in /home/program/public_html/phprndxmlfeeds.php on line 185

Warning: fopen(http://www.osnews.com/files/recent.rdf ) [function.fopen]: failed to open stream: no suitable wrapper could be found in /home/program/public_html/phprndxmlfeeds.php on line 185
cannot open the site