note 42570 deleted from ref.xml by didou

From: Date: Thu, 03 Feb 2005 19:47:39 +0000
Subject: note 42570 deleted from ref.xml by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-84465@lists.php.net to get a copy of this message
Note Submitter: rich at launchcode dot co dot uk ---- The makeXMLTree function posted below proved to be a life-saver for me in a recent project, however I had to modify it to work in an E_ALL environment (the original will throw up a load of constant Warnings in the eval'd code), so I hope some of you find the following variation of it useful: <?php $result = makeXMLTree($xml); print_r($result); function makeXMLTree ($data) { $output = array(); $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, $data, $values, $tags); xml_parser_free($parser); $hash_stack = array(); foreach ($values as $key => $val) { switch ($val['type']) { case 'open': array_push($hash_stack, $val['tag']); break; case 'close': array_pop($hash_stack); break; case 'complete': array_push($hash_stack, $val['tag']); eval("\$output['" . implode($hash_stack, "']['") . "'] = \"{$val['value']}\";"); array_pop($hash_stack); break; } } return $output; } ?>

« previous php.notes (#84465) next »