Mega Code Archive

 
Categories / Php / Code Snippets
 

Display latest news from Slashdot

<?php $xmlfile = fopen("http://example", "r"); if(!$xmlfile)die("cannot open the xml file"); $readfile = fread($xmlfile ,40000); $searchfile = eregi("<item>(.*)</item>", $readfile ,$arrayreg); $filechunks = explode("<item>", $arrayreg[0]); $count = count($filechunks); echo "<table border='1'>"; echo "<th colspan='3'>latest news</th>"; for($i=1 ; $i<=$count-1 ;$i++) { ereg("<title>(.*)</title>",$filechunks[$i], $title); ereg("<link>(.*)</link>",$filechunks[$i], $links); ereg("<description>(.*)</description",$filechunks[$i],$desc); echo "<tr><td>"; echo $title[1]; echo "</td><td>"; echo "<a href ='$links[1]'\>$links[1]</a>"; echo "</td><td>"; echo $desc[1]; echo "</td></tr>"; } echo "</table>"; ?>