成都创新互联网站制作重庆分公司

php将xml转换为数组

  1. 函数:
    /*
    @desc:xml转数组
    @param data xml字符串
    @return arr 解析出的数组
    */
    function xmltoarray($data){
    $obj = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
    $json = json_encode($obj);
    $arr = json_decode($json, true);      
    return $arr;
    }
  2. 测试:
    a. 代码:
     
    
    Forty What?
    Joe
    Jane
    
    I know that's the answer -- but what's the question?
    
    
    XML;
    $arr = xmltoarray($string);
    var_dump($arr);

    b. 输出:

    创新互联成立十余年来,这条路我们正越走越好,积累了技术与客户资源,形成了良好的口碑。为客户提供网站制作、网站设计、网站策划、网页设计、域名注册、网络营销、VI设计、网站改版、漏洞修补等服务。网站是否美观、功能强大、用户体验好、性价比高、打开快等等,这些对于网站建设都非常重要,创新互联通过对建站技术性的掌握、对创意设计的研究为客户提供一站式互联网解决方案,携手广大客户,共同发展进步。

    array(4) {
    ["title"]=>
    string(11) "Forty What?"
    ["from"]=>
    string(3) "Joe"
    ["to"]=>
    string(4) "Jane"
    ["body"]=>
    string(57) "
    I know that's the answer -- but what's the question?
    "
    }

网站栏目:php将xml转换为数组
URL链接:http://cxhlcq.com/article/pepihi.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部