<?php
    //1、把整个文件读入一个字符串中:(用于接收xml文件)
    $xml_file = file_get_contents('php://input');
    //2、转换形式良好的 XML 字符串为 SimpleXMLElement 对象,然后输出对象的键和元素:(用于处理接收到的xml数据,将其转换成对象)
    $xml_object = simplexml_load_string($xml_file, 'SimpleXMLElement', LIBXML_NOCDATA);
    //3、对象转成json
    $xml_json=json_encode($xml_object);
    //4、json再转成数组
    $xml_arr=json_decode($xml_json,true);
    //最后打印输出
    echo "<pre>";
    var_dump($xml_arr);
最后修改:2022 年 12 月 20 日
如果觉得我的文章对你有用,请随意赞赏