php XML转json

$x=new xml();
$x->xml2json();
class xml
{
function xml2json()
{
$xml_object=NULL;
if (file_exists('test.xml'))
{
$xml_object = simplexml_load_file('test.xml');
}
else
{
exit('Failed to open test.xml.');
}
$xml_json=json_encode($xml_object);
echo $xml_json;
}
}
原文地址:https://www.cnblogs.com/mybest/p/2285808.html