php把读取xml 文档并转换成json数据代码

作者:袖梨 2022-06-24

/*

ps教程="20" maxPage="1" num="1" serverIP="58.57.65.195">



*/

$url = "http://www.111com.net/xml.xml";

$dom = new DOMDocument();
$dom->load($url);
$root = $dom->documentElement;
$arr=array();
foreach ($root->childNodes as $item)
{
        if($item->hasChildNodes())
        {
                $tmp=array();
                foreach($item->childNodes as $one)
                {
                        $tmp[$one->tagName]=$one->nodeValue;
                }
               
                $arr[$item->tagName]=$tmp;
        }
}

$jsonStr = json_encode($arr);

var_dump($jsonStr);

/*

*/
?>

相关文章

精彩推荐