首頁  >  文章  >  php教程  >  php将xml数据转化为数组(array)

php将xml数据转化为数组(array)

WBOY
WBOY原創
2016-06-06 19:55:272146瀏覽

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 用php实现将xml数据转化为数组(array): 将xml转化为数组,使用正则表达式对xml数据进行匹配.代码如下: function xml_to_array( $xml ){ $reg = “/(\w+)[^]*([\x00-\xFF]*)\/\1/”; if(preg_match_all

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

    用php实现将xml数据转化为数组(array):

    将xml转化为数组,使用正则表达式对xml数据进行匹配.代码如下:

    function xml_to_array( $xml ){

    $reg = “/]*>([\x00-\xFF]*)/”;

    if(preg_match_all($reg, $xml, $matches))

    {

    $count = count($matches[0]);

    for($i = 0; $i

    {

    $subxml= $matches[2][$i];

    $key = $matches[1][$i];

    if(preg_match( $reg, $subxml ))

    {

    $arr[$key] = xml_to_array( $subxml );

    }else{

    $arr[$key] = $subxml;

    }

    }

    }

    return $arr;

    }

    function xmltoarray( $xml ){

    $arr = xml_to_array($xml);

    $key = array_keys($arr);

    return $arr[$key[0]];

    }

php将xml数据转化为数组(array)

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn