note 90622 deleted from function.xml-parse-into-struct by sobak

From: Date: Sat, 10 Dec 2016 23:26:27 +0000
Subject: note 90622 deleted from function.xml-parse-into-struct by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208466@lists.php.net to get a copy of this message
Note Submitter: Adam Tylmad ---- Thanx to jukea i've upgraded the characterData-function to allow the value 0. Here is the new complete code: <?php class XMLParser { var $path; var $result; function cleanString($string) { return trim(str_replace("'", "&#39;", $string)); } function XMLParser($encoding, $data) { $this->path = "\$this->result"; $this->index = 0; $xml_parser = xml_parser_create($encoding); xml_set_object($xml_parser, &$this); xml_set_element_handler($xml_parser, 'startElement', 'endElement'); xml_set_character_data_handler($xml_parser, 'characterData'); xml_parse($xml_parser, $data, true); xml_parser_free($xml_parser); } function startElement($parser, $tag, $attributeList) { $this->path .= "->".$tag; eval("\$data = ".$this->path.";"); if (is_array($data)) { $index = sizeof($data); $this->path .= "[".$index."]"; } else if (is_object($data)) { eval($this->path." = array(".$this->path.");"); $this->path .= "[1]"; } foreach($attributeList as $name => $value) eval($this->path."->".$name. " = '".XMLParser::cleanString($value)."';"); } function endElement($parser, $tag) { $this->path = substr($this->path, 0, strrpos($this->path, "->")); } function characterData($parser, $data) { if (strlen($data = XMLParser::cleanString($data))) eval($this->path." = '$data';"); } } ?>

« previous php.notes (#208466) next »