您好,欢迎访问一九零五行业门户网

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

欢迎进入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]];
    }
其它类似信息

推荐信息