I am trying to convert xml to json in php. If I do a simple convert using simple xml and json_encode none of the attributes in the xml show.
$xml = simplexml
Best solution which works like a charm
$fileContents= file_get_contents($url);
$fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
$fileContents = trim(str_replace('"', "'", $fileContents));
$simpleXml = simplexml_load_string($fileContents);
//$json = json_encode($simpleXml); // Remove // if you want to store the result in $json variable
echo ''.json_encode($simpleXml,JSON_PRETTY_PRINT).'
';
Source