1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
<?php
class rss
{
var $item = FALSE ;
var $chem = '' ;
var $id ;
var $number ;
var $id_programme ;
var $name ;
var $description ;
var $manufacturer ;
var $merchant ;
var $deeplink ;
var $image_medium ;
var $image_large ;
var $resume = array() ;
function ouvre($sax, $nom, $attributs)
{
$this->chem .= '/'.$nom;
if ($this->chem=='/flux/product')
{
$this->id = '';
$this->number = '';
$this->id_programme = '';
$this->name = '';
$this->description = '';
$this->manufacturer = '';
$this->merchant = '';
$this->deeplink = '';
$this->image_medium = '';
$this->image_large = '';
$this->item = TRUE;
$id = $attributs['id'];
$number = $attributs['number'];
echo '$id vaut:' . $id . '<br />';
echo '$number vaut:' . $number . '<br />';
}
elseif ($this->chem=='/flux/product/affiliateprogram')
{
$id_programme = $attributs['id'];
echo '$id_programme vaut:' . $id_programme . '<br />';
}
}
function ferme($sax,$nom)
{
if ($this->chem=='/flux/product')
{
$name = htmlentities($this->name, ENT_QUOTES, 'UTF-8');
$description = htmlentities($this->description, ENT_QUOTES, 'UTF-8');
$manufacturer = htmlentities($this->manufacturer, ENT_QUOTES, 'UTF-8');
$merchant = htmlentities($this->merchant, ENT_QUOTES, 'UTF-8');
$deeplink = htmlentities($this->deeplink, ENT_QUOTES, 'UTF-8');
echo "$name<br />";
echo "$description<br />";
echo "$manufacturer<br />";
echo "$merchant<br />";
echo "$deeplink<br /><br />";
}
$pos = strrpos($this->chem, '/');
$this->chem = substr($this->chem, 0, $pos);
}
function texte($sax, $texte)
{
if ($this->chem == '/flux/product/info/name')
{
$this->name .= $texte;
}
elseif ($this->chem == '/flux/product/info/description')
{
$this->description .= $texte;
}
elseif ($this->chem == '/flux/product/info/manufacturer')
{
$this->manufacturer .= $texte;
}
elseif ($this->chem == '/flux/product/category/merchant')
{
$this->merchant .= $texte;
}
elseif ($this->chem == '/flux/product/links/deeplink')
{
$this->deeplink .= $texte;
}
}
}
$rss = new rss();
$sax = xml_parser_create();
xml_parser_set_option($sax, XML_OPTION_CASE_FOLDING, FALSE); // laisse le nom des balise en minuscule
xml_set_object($sax, $rss);
xml_set_element_handler($sax, 'ouvre', 'ferme');
xml_set_character_data_handler($sax, 'texte');
$fichier = 'http://www.mon-site.fr/flux.xml';
$fp = fopen($fichier, 'r');
while ($xml = fread($fp, 1024))
{
xml_parse($sax, $xml, feof($fp)); // On execute
}
xml_parser_free($sax);
?> |
Partager