"-", "“" => "\"", "”" => "\"", "’" => "'");//, "& " => "& "); $string5 = strtr($string4, $trans); } return $string; } function _startElement($parser, $name, $attrs) { // xml if ($this->_insideitem) { $this->_tag = $name; } elseif ($name == "ITEM") { $this->_insideitem = true; } } function _endElement($parser, $name) { // xml if ($name == "ITEM") { if ($this->_recordinc<$this->recordmax) // { // gestion utf-8 $this->_title = $this->filtertext($this->_title); $this->_description = $this->filtertext($this->_description); // affectation dans le tableau $this->item[$this->_recordinc] = new NewsItem; $this->item[$this->_recordinc]->url = trim($this->_link); $this->item[$this->_recordinc]->title = htmlspecialchars(trim($this->_title)); $this->item[$this->_recordinc]->description = htmlspecialchars(trim($this->_description)); // incrementation $this->_recordinc++; } $this->recordcount = $this->_recordinc; $this->_title = ""; $this->_description = ""; $this->_link = ""; $this->_insideitem = false; } } function _characterData($parser, $data) { // xml if ($this->_insideitem) { switch ($this->_tag) { case "TITLE": $this->_title .= $data; break; case "DESCRIPTION": $this->_description .= $data; break; case "LINK": $this->_link .= $data; break; } } } function xml_main ($file) { $OK = 1; // fonction principale pour lancement de la lecture $this->_recordinc =0; // creation de l'objet parser xml $xml_parser = xml_parser_create(); // on indique que le parser est dans un objet ! xml_set_object($xml_parser, $this); xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,1); xml_set_element_handler($xml_parser, _startElement, _endElement); xml_set_character_data_handler($xml_parser, _characterData); // ouverture du fichier RSS : le @ permet de ne pas afficher // le message d'erreur si probleme a l'ouverture $fp = @fopen($file,"r"); //or die("Error reading RSS data."); if ($fp) { while ($data = fread($fp, 4096)) { $ret = xml_parse($xml_parser, $data, feof($fp)); if (!$ret) { $OK = 0; $this->errormsg = sprintf("Erreur XML : %s à la ligne %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)); } } fclose($fp); } else { $OK = 0; $this->errormsg = "Une erreur est survenue lors de l'ouverture du fichier RSS."; } xml_parser_free($xml_parser); return $OK; } function run ($filename) { // point d'entree public $ret = $this->xml_main ($filename); return $ret; } }; ?>