- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
- <?php
- /////////////////////////////////////////////////////////////////////////////////
- // PHPRSSReader.php - d'après HTML Reader par Jorge Solis
- // traduit et simplifié par Pierre Rouarch pour tenir en un fichier
- ////////////////////////////////////////////////////////////////////////////////
-
- class xml {
- var $parser;
- function parse($xmlstring){
- $this->parser = xml_parser_create();
- xml_set_object($this->parser, $this);
- xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
- xml_set_element_handler($this->parser, "tag_open", "tag_close");
- xml_set_character_data_handler($this->parser, "cdata");
-
- // Initialisation
- $this->node_stack = array();
- $this->tag_open(null, "root", array());
-
- xml_parse($this->parser, $xmlstring);
- xml_parser_free($this->parser);
-
- $rnode = array_pop($this->node_stack);
-
- return($rnode);
- }
-
- function tag_open($parser, $tag, $attributes){
- // creation d'un nouveau node...
- $node = array();
- $node["_NAME"] = $tag;
- foreach ($attributes as $key => $value) {
- $node[$key] = $value;
- }
- $node["_DATA"] = "";
- $node["_ELEMENTS"] = array();
-
- // ajouter le nouveau node à la fin de la pile de node
- array_push($this->node_stack, $node);
- }
-
- function cdata($parser, $cdata){
- // ajouter les données au dernier node de la pile
- $lastnode = count($this->node_stack);
- $this->node_stack[$lastnode-1]["_DATA"] .= $cdata;
- }
-
- function tag_close($parser, $tag){
- // suppression de la pile
- $node = array_pop($this->node_stack);
- $node["_DATA"] = trim($node["_DATA"]);
-
- // and ajout comme élément à la fin de la pile...
- $lastnode = count($this->node_stack);
- array_push($this->node_stack[$lastnode-1]["_ELEMENTS"], $node);
- }
- } // end of class xml
-
-
-
- // recupération de l' adresse du RSS avec le paramètre rssurl
- $rssurl = $HTTP_GET_VARS["rssurl"];
- //////////////////////////////////////////////////////////////////////////////////////////////////
- //Modifiez ici pour mettre l'adresse URL de votre RSS au cas ou aucun argument n'est passé:
- // exemple :
- // http://www.votresite.com/PHPRSSReader.php?rssurl=http://www.votresite.com/votrefichierrss
- /////////////////////////////////////////////////////////////////////////////////////////////
- if (!$rssurl ) $rssurl = "http://www.u-blog.net/itcom3/rss";
-
- // récupération du fichier par paquets de 4096
- $fp = fopen($rssurl, "r");
- while (!feof ($fp)) $data .= fgets($fp, 4096);
- fclose ($fp);
- $initPos = strpos($data, "<channel>"); // Saut de l'entête
-
- //parse les données
-
- $xml_parser = new xml();
- $data = substr($data, $initPos);
- $root_node = $xml_parser->parse($data);
- $channel = array_shift($root_node["_ELEMENTS"]);
-
- //Récupération de certaines données du RSS (Voir les specifications rss 0.91, 0.92 et 2.0)
- ////// Récupération entête de channel /////////////////////////////////////////////////////////
- foreach ($channel["_ELEMENTS"] as $item){
- // suppression des antislashs
- if($item[_NAME]=="title") $base_name=stripslashes($item[_DATA]);
- if($item[_NAME]=="link") $base_url=stripslashes($item[_DATA]);
- if($item[_NAME]=="description") $base_desc=stripslashes($item[_DATA]);
- }
- $base = "<b>Web: </b><a href=\"$base_url\" target=\"_new\">$base_name</a><br>$base_desc<br>";
- /////////////////////////////////////////////////////////////////////////
- ////////// Récupération de chaque Item --> titre, adresse url, date de publication, description //////////////////////////////////////////////////////
- foreach ($channel["_ELEMENTS"] as $item){
-
- if($item[_NAME]=="item") {
- // suppression des antislashs
- foreach ($item["_ELEMENTS"] as $tag){
- if($tag["_NAME"]=="title") $news_title=stripslashes($tag[_DATA]);
- if($tag["_NAME"]=="link") $news_url=stripslashes($tag[_DATA]);
- if($tag["_NAME"]=="pubDate") $news_pubDate=stripslashes($tag[_DATA]);
- if($tag["_NAME"]=="description") $news_desc=stripslashes($tag[_DATA]);
- }
- $news .= "<p>$news_pubDate<br><b>$news_title</b><br>$news_desc<br><a href=\"$news_url\" target=\"_new\">$news_url</a><hr></p>";
- }
- }
- ////////////////////////////////////////////////////////////////////////////////
- ?>
- <html>
- <head>
- <title>Sample RSS Reader in PHP</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- </head>
- <body>
-
-
-
- <?php print($news) ?>
- <?php print($base) ?>
-
- </body>
- </html>
-
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<?php
/////////////////////////////////////////////////////////////////////////////////
// PHPRSSReader.php - d'après HTML Reader par Jorge Solis
// traduit et simplifié par Pierre Rouarch pour tenir en un fichier
////////////////////////////////////////////////////////////////////////////////
class xml {
var $parser;
function parse($xmlstring){
$this->parser = xml_parser_create();
xml_set_object($this->parser, $this);
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($this->parser, "tag_open", "tag_close");
xml_set_character_data_handler($this->parser, "cdata");
// Initialisation
$this->node_stack = array();
$this->tag_open(null, "root", array());
xml_parse($this->parser, $xmlstring);
xml_parser_free($this->parser);
$rnode = array_pop($this->node_stack);
return($rnode);
}
function tag_open($parser, $tag, $attributes){
// creation d'un nouveau node...
$node = array();
$node["_NAME"] = $tag;
foreach ($attributes as $key => $value) {
$node[$key] = $value;
}
$node["_DATA"] = "";
$node["_ELEMENTS"] = array();
// ajouter le nouveau node à la fin de la pile de node
array_push($this->node_stack, $node);
}
function cdata($parser, $cdata){
// ajouter les données au dernier node de la pile
$lastnode = count($this->node_stack);
$this->node_stack[$lastnode-1]["_DATA"] .= $cdata;
}
function tag_close($parser, $tag){
// suppression de la pile
$node = array_pop($this->node_stack);
$node["_DATA"] = trim($node["_DATA"]);
// and ajout comme élément à la fin de la pile...
$lastnode = count($this->node_stack);
array_push($this->node_stack[$lastnode-1]["_ELEMENTS"], $node);
}
} // end of class xml
// recupération de l' adresse du RSS avec le paramètre rssurl
$rssurl = $HTTP_GET_VARS["rssurl"];
//////////////////////////////////////////////////////////////////////////////////////////////////
//Modifiez ici pour mettre l'adresse URL de votre RSS au cas ou aucun argument n'est passé:
// exemple :
// http://www.votresite.com/PHPRSSReader.php?rssurl=http://www.votresite.com/votrefichierrss
/////////////////////////////////////////////////////////////////////////////////////////////
if (!$rssurl ) $rssurl = "http://www.u-blog.net/itcom3/rss";
// récupération du fichier par paquets de 4096
$fp = fopen($rssurl, "r");
while (!feof ($fp)) $data .= fgets($fp, 4096);
fclose ($fp);
$initPos = strpos($data, "<channel>"); // Saut de l'entête
//parse les données
$xml_parser = new xml();
$data = substr($data, $initPos);
$root_node = $xml_parser->parse($data);
$channel = array_shift($root_node["_ELEMENTS"]);
//Récupération de certaines données du RSS (Voir les specifications rss 0.91, 0.92 et 2.0)
////// Récupération entête de channel /////////////////////////////////////////////////////////
foreach ($channel["_ELEMENTS"] as $item){
// suppression des antislashs
if($item[_NAME]=="title") $base_name=stripslashes($item[_DATA]);
if($item[_NAME]=="link") $base_url=stripslashes($item[_DATA]);
if($item[_NAME]=="description") $base_desc=stripslashes($item[_DATA]);
}
$base = "<b>Web: </b><a href=\"$base_url\" target=\"_new\">$base_name</a><br>$base_desc<br>";
/////////////////////////////////////////////////////////////////////////
////////// Récupération de chaque Item --> titre, adresse url, date de publication, description //////////////////////////////////////////////////////
foreach ($channel["_ELEMENTS"] as $item){
if($item[_NAME]=="item") {
// suppression des antislashs
foreach ($item["_ELEMENTS"] as $tag){
if($tag["_NAME"]=="title") $news_title=stripslashes($tag[_DATA]);
if($tag["_NAME"]=="link") $news_url=stripslashes($tag[_DATA]);
if($tag["_NAME"]=="pubDate") $news_pubDate=stripslashes($tag[_DATA]);
if($tag["_NAME"]=="description") $news_desc=stripslashes($tag[_DATA]);
}
$news .= "<p>$news_pubDate<br><b>$news_title</b><br>$news_desc<br><a href=\"$news_url\" target=\"_new\">$news_url</a><hr></p>";
}
}
////////////////////////////////////////////////////////////////////////////////
?>
<html>
<head>
<title>Sample RSS Reader in PHP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php print($news) ?>
<?php print($base) ?>
</body>
</html>