php 将xml 数据转化为json

PHP :

public function xml_to_json($source) {
    if(is_file($source)){ //传的是文件,还是xml的string的判断
      $xml_array=simplexml_load_file($source);

    }else{

      $xml_array=simplexml_load_string($source);
    }

    $json = json_encode($xml_array);
    return $json;
  }

你可能感兴趣的:(php 将xml 数据转化为json)