PHP xml转JSON 实例

<?php
header('Content-type: application/json'); 
$api = xml('https://umqun.com/sitemap.xml');
echo json_encode($api,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
//xml转JSON
function xml($url){
	$api = file_get_contents($url);
	$xml=simplexml_load_string($api,'SimpleXMLElement',LIBXML_NOCDATA);
	$json = json_encode($xml,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
	$data = json_decode($json,true);
	return $data;
}