1

Topic: about the use of rss 2

Hi,

I'm trying to use a rss feed but it does not work very good.

<?php
$site = "http://permanent.nouvelobs.com/cgi/rss/permanent_une";
$fp = @fopen($site,"r");
while(!feof($fp)) $raw .= @fgets($fp, 4096);
fclose($fp);

if( eregi("<item>(.*)</item>", $raw, $rawitems ) ) {
 $items = explode("<item>", $rawitems[0]);

 for( $i = 0; $i < count($items)-1; $i++ ) {
  eregi("<title>(.*)</title>",$items[$i+1], $title );
  eregi("<url>(.*)</url>",$items[$i+1], $url );
  eregi("<categorie>(.*)</categorie>",$items[$i+1], $cat);
  echo "<li><a href='".$url[1]."'>".$title[1]."</a> - ".$cat[1];
 }
}

?>

With that code the problem is that the link are not good. See here for example http://www.oyre.net/test.php
You'll see that the link is always the same. It's not normal. There is a problem when reading the link.

Can anybody help me?

Ludo,

2

Re: about the use of rss 2

In fact, I solved my problem alone puting that:

<?
// Lecture d'un fichier XML
function lit_xml($fichier,$item,$champs) {
   // on lit le fichier
   if($chaine = @implode("",@file($fichier))) {
      // on explode sur <item>
      $tmp = preg_split("/<\/?".$item.">/",$chaine);
      // pour chaque <item>
      for($i=1;$i<sizeof($tmp)-1;$i+=2)
         // on lit les champs demandés <champ>
         foreach($champs as $champ) {
            $tmp2 = preg_split("/<\/?".$champ.">/",$tmp[$i]);
            // on ajoute au tableau
            $tmp3[$i-1][] = @$tmp2[1];
         }
      // et on retourne le tableau
      return $tmp3;
   }
}

// Exemple :
$xml = 

lit_xml("http://permanent.nouvelobs.com/cgi/rss/permanent_une","item",array("title","link","pubDate","description"));
// et on affiche...
echo "<ul>";
foreach($xml as $row) {
   echo "<li>"
      ."<font size=2 color=gray>[".date("d/m/Y",strtotime($row[2]))."]</font> "
      ."<A target=_blank href='".$row[1]."'>".$row[0]."</A><br>"
      .$row[3]
      ."</li>";
}
echo "</ul>";
?>

Now, do you know how I can do to have only 10 items?

Ludo,