>  기사  >  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으로 문의하세요.