XML to JSON conversion in PHP SimpleXML

前端 未结 2 1087
面向向阳花
面向向阳花 2021-01-24 01:11
            $data = \"
            Y
            
            

        
2条回答
  •  情深已故
    2021-01-24 01:59

    $fileContents= file_get_contents("https://www.feedforall.com/sample.xml");
    $fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
    $fileContents = trim(str_replace('"', "'", $fileContents));
    $simpleXml = simplexml_load_string($fileContents);
    $json = json_encode($simpleXml);
    $array = json_decode($json,TRUE); // convert the JSON-encoded string to a PHP variable
    return $array;
    

    I'ts Better example:

提交回复
热议问题