Answers for "how to convert xml to json in php"

PHP
0

xml to object php

$object = json_decode(json_encode(simplexml_load_string($xml)));
Posted by: Guest on May-07-2020
1

php xml to json

$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);
Posted by: Guest on February-05-2022
0

php xml to json

foreach($xml->children() as $state)
{
    $states[]= array('state' => (string)$state->name); 
}       
echo json_encode($states);
Posted by: Guest on February-05-2022

Browse Popular Code Answers by Language