note 113951 deleted from function.xml-parse-into-struct by cmb
| From: | cmb@php.net | Date: | Tue, 09 Oct 2018 12:24:48 +0000 |
| Subject: | note 113951 deleted from function.xml-parse-into-struct by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-209411@lists.php.net to get a copy of this message | ||
Note Submitter: rejeesh_designdirect at yahoo dot com
----
Simple method for format XML to Array
function xml2array($xml){
$opened = array();
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $xml, $xmlarray);
$array = array();
$arrsize = sizeof($xmlarray);
for($j=0;$j<$arrsize;$j++){
$val = $xmlarray[$j];
switch($val["type"]){
case "open":
$opened[$val["tag"]] = $array;
unset($array);
break;
case "complete":
$array[$val["tag"]][] = $val["value"];
break;
case "close":
$opened[$val["tag"]] = $array;
$array = $opened;
break;
}
}
return $array;
}