<html> <head> <title>Parser les news</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>
<body> <?php if(!isset($url)) $url="http://www.myphpsoft.net/news/backend/";?> <form name="form1" method="get" action=""> <table width="100%" border="0" cellspacing="0" cellpadding="7"> <tr> <td bgcolor="#EEEEEE"><strong>URL</strong>: <input name="url" type="text" id="url" value="<?php echo $url; ?>" size="70"> <input type="submit" name="Submit" value="Envoyer"> </td> </tr> </table> </form> <?php /** * Function read file RSS/XML (Not need for the extension XML in PHP) * * @param type * $urlxmlfile string * $namesite string * $bullet bool * $target string */ function ReadRSSOutXML($urlxmlfile,$namesite,$wantdescrible=false,$bullet=false,$target='_blank'){ $file = @fopen($urlxmlfile, "r"); if($file){ $readfile = @fread($file ,40000); $searchfile = eregi("<item>(.*)</item>", $readfile ,$arrayreg); $filechunks = explode("<item>", $arrayreg[0]); $count = count($filechunks); for($i=1 ; $i<=$count-1 ;$i++){ ereg("<title>(.*)</title>",$filechunks[$i], $title); ereg("<link>(.*)</link>",$filechunks[$i], $links); ereg("<description>(.*)</description>",$filechunks[$i], $description); $result.=(($bullet==true) ? "<li>" : "")."<a href =\"$links[1]\" target=\"$target\">$title[1]</a> ".(($wantdescrible==true) ? "<br>".$description[1] : "")." ".(($bullet==true) ? "</li>" : "<br>")."\n"; } } @fclose($fSource); return $result; }
/** * Function read file format text with '%%' separator * Format use : * %% * date * titre * lien * %% * * @param type * $urlxmlfile string * $nomsite string * $bullet bool * $target string */ function ReadTXT($urltxtfile,$nomsite,$bullet=false,$target='_blank'){ $fSource = @fopen($urltxtfile,'r'); if ($fSource){ while(! feof($fSource)){ $buffer = chop(fgets($fSource,256)); if ($buffer == "%%"){ $date = chop(fgets($fSource,256)); $titre = chop(fgets($fSource,256)); $lien = chop(fgets($fSource,256)); if ($titre!="") $result.= (($bullet==true) ? "<li>" : "")." <a href=\"$lien\" target=\"$target\">$titre</a>".(($bullet==true) ? "</li>" : "<br>")."\n"; } } } @fclose($fSource); return $result; } ?> <?php $urlrss= $url."backend.rss"; $urltxt= $url."backend.txt"; echo "<h3>Résultat via le fichier RSS(XML) - ".$urlrss."</h3>"; echo ReadRSSOutXML("$urlrss","MyPHPSoft",true); echo "<h3>Résultat via le fichier TXT - ".$urltxt."</h3>"; echo ReadTXT("$urltxt","MyPHPSoft",true); ?> <h3>Sources </h3> <table width="100%" border="0" cellspacing="0" cellpadding="6"> <tr> <td bgcolor="#EEEEEE"> <?php show_source('parser_news.php'); ?> </td> </tr> </table> </body> </html>
|