20181212

xml2json

function xml2json($fileContents) {
  $fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
  $fileContents = trim(str_replace('"', "'", $fileContents));
  $simpleXml = simplexml_load_string($fileContents);
  $json = json_encode($simpleXml,1);
  return $json;
}

沒有留言: