function xml_to_array($file) { if (defined('AGILE_CORE_CACHE_DIR') && AGILE_CORE_CACHE_DIR != '') { $tfile = AGILE_CORE_CACHE_DIR . "xml-" . md5($file); if (file_exists($tfile)) { #clearstatcache(); #$mt = filemtime($file); if (@filemtime($file) <= filemtime($tfile)) { #echo "cached: $file<br>"; return unserialize(file_get_contents($tfile)); } } #echo "cache miss: $file<br>"; } if (!is_callable('simplexml_load_file') || !is_callable('dom_import_simplexml')) { // call old XML to array class $arr = xmlFileToArray($file, $includeTopTag = true, $lowerCaseTags = true); } else { // use SimpleXML class if (!is_file($file)) { return false; } $xml = simplexml_load_file($file); if (is_object($xml)) { $dom = dom_import_simplexml($xml); $arr["{$dom->tagName}"] = SimpleXML2Array($xml); } } if (defined('AGILE_CORE_CACHE_DIR') && AGILE_CORE_CACHE_DIR != '') { $fp = fopen($tfile, "wb"); if ($fp) { fwrite($fp, serialize($arr)); fclose($fp); } } return $arr; }
function xml2array($xml) { $array = (array) $xml; if (count($array) == 0) { $array = (string) $xml; } if (is_array($array)) { //recursive Parser foreach ($array as $key => $value) { if (is_object($value)) { if (strpos(get_class($value), "SimpleXML") !== false) { $array[$key] = SimpleXML2Array($value); } } else { $array[$key] = SimpleXML2Array($value); } } } return $array; }