Server : Apache
System : Linux iZ2vcgyutqttsd1p850kl8Z 3.10.0-1160.92.1.el7.x86_64 #1 SMP Tue Jun 20 11:48:01 UTC 2023 x86_64
User : www ( 1000)
PHP Version : 5.6.40
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Directory :  /www/wwwroot/saimikebio.com/mobile/include/kernel/library/
Upload File :
Current Directory [ Writeable ] Root Directory [ Writeable ]


Current File : /www/wwwroot/saimikebio.com/mobile/include/kernel/library/Xml.class.php
<?php



// +----------------------------------------------------------------------

// | EcTouch [ 专注移动电商: 商创网络科技 ]

// +----------------------------------------------------------------------

// | Copyright (c) 2014 http://ectouch.cn All rights reserved.

// +----------------------------------------------------------------------

// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )

// +----------------------------------------------------------------------

// | Author: EcTouch Team <zhong@ecmoban.com> (QQ: 2880175560)

// +----------------------------------------------------------------------



//xml解析成数组

class Xml {



    public static function decode($xml) {

        $values = array();

        $index = array();

        $array = array();

        $parser = xml_parser_create('utf-8');

        xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);

        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);

        xml_parse_into_struct($parser, $xml, $values, $index);

        xml_parser_free($parser);

        $i = 0;

        $name = $values[$i]['tag'];

        $array[$name] = isset($values[$i]['attributes']) ? $values[$i]['attributes'] : '';

        $array[$name] = self::_struct_to_array($values, $i);

        return $array;

    }



    private static function _struct_to_array($values, &$i) {

        $child = array();

        if (isset($values[$i]['value']))

            array_push($child, $values[$i]['value']);



        while ($i++ < count($values)) {

            switch ($values[$i]['type']) {

                case 'cdata':

                    array_push($child, $values[$i]['value']);

                    break;



                case 'complete':

                    $name = $values[$i]['tag'];

                    if (!empty($name)) {

                        $child[$name] = ($values[$i]['value']) ? ($values[$i]['value']) : '';

                        if (isset($values[$i]['attributes'])) {

                            $child[$name] = $values[$i]['attributes'];

                        }

                    }

                    break;



                case 'open':

                    $name = $values[$i]['tag'];

                    $size = isset($child[$name]) ? sizeof($child[$name]) : 0;

                    $child[$name][$size] = self::_struct_to_array($values, $i);

                    break;



                case 'close':

                    return $child;

                    break;

            }

        }

        return $child;

    }



}



?>