php json to xml
<?php
$xml = simplexml_load_string($xml_string);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
?>
PHP convert XML to JSON
$xml = simplexml_load_file("states.xml");
echo json_encode($xml);
php json to xml
$xml = new SimpleXMLElement('<root/>');
$this->arrayToXml($array, $xml);
function arrayToXml($array, &$xml){
foreach ($array as $key => $value) {
if(is_int($key)){
$key = "e";
}
if(is_array($value)){
$label = $xml->addChild($key);
$this->arrayToXml($value, $label);
}
else {
$xml->addChild($key, $value);
}
}
}
本文链接地址:https://const.net.cn/640.html