Answers
JSON TO XML :
public function json_to_xml($source,$charset='utf8') {
if(emptyempty($source)){
return false;
}
$array = json_decode($source); //php5,以及以上,如果是更早版本,請下載JSON.php
$xml ='<!--l version="1.0" encoding="'.$charset.'-->';
$xml .= $this->change($array);
return $xml;
}
public function change($source) {
$string="";
foreach($source as $k=>$v){
$string .="<".$k.">";
if(is_array($v) || is_object($v)){ //判断是否是数组,或者,对像
$string .= $this->change($v); //是数组或者对像就的递归调用
}else{
$string .=$v; //取得标签数据
}
$string .="";
}
return $string;
}
XML TO JSON :
Amaris
answered 12 years, 4 months ago