note 70916 added to function.xml-parse-into-struct
| From: | A3 at osu1 dot php dot net | Date: | Sat, 04 Nov 2006 01:28:29 +0000 |
| Subject: | note 70916 added to function.xml-parse-into-struct | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119357@lists.php.net to get a copy of this message | ||
XML -> Array
<?
$data = '<root><a><b x="s"
a="2">asdf</b><c></c></a></root>';
$p = xml_parser_create();
xml_parse_into_struct($p, $data, $vals);
xml_parser_free($p);
$key = $output = array();
foreach ($vals as $id=>$item) {
if ($item["type"]=="open" || $item["level"]>count($key)) {//
&& count($key)<=$item["level"])
array_push($key, $id);
$temp = array("tag"=>$item["tag"],
"value"=>"", "attributes"=>array());
eval("\$output[".implode("][", $key)."] = \$temp;");
}
if ($item["type"]=="close" || $item["level"]<count($key))//
&& $item["level"]>=count($key))
array_pop($key);
if (isset($item["attributes"]))
eval("\$output[".implode("][", $key)."]['attributes'] =
array_merge(\$output[".implode("][", $key)."]['attributes'],
\$item['attributes']);");
if (isset($item["value"]))
eval("\$output[".implode("][", $key)."]['value'] .=
\$item['value'];");
}
?>
----
Server IP: 195.149.248.161
Probable Submitter: 87.120.19.175
----
Manual Page -- http://www.php.net/manual/en/function.xml-parse-into-struct.php
Edit -- https://master.php.net/note/edit/70916
Del: integrated -- https://master.php.net/note/delete/70916/integrated
Del: useless -- https://master.php.net/note/delete/70916/useless
Del: bad code -- https://master.php.net/note/delete/70916/bad+code
Del: spam -- https://master.php.net/note/delete/70916/spam
Del: non-english -- https://master.php.net/note/delete/70916/non-english
Del: in docs -- https://master.php.net/note/delete/70916/in+docs
Del: other reasons-- https://master.php.net/note/delete/70916
Reject -- https://master.php.net/note/reject/70916
Search -- https://master.php.net/manage/user-notes.php