note 42570 added to ref.xml
| From: | richatlaunchcodedotcodotuk at rn2 dot php dot net | Date: | Fri, 21 May 2004 19:08:08 +0000 |
| Subject: | note 42570 added to ref.xml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69920@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.xml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42570
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42570&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42570&report=yes
Search -- http://master.php.net/manage/user-notes.php