⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xml.php

📁 一个基于web的rpg游戏源代码
💻 PHP
字号:
<?php/*** Netlands World Server is the coordinator of the VR in the Netlands Project* Copyright (C) 2002 Ricard Pillosu* * This program is free software; you can redistribute it and/or* modify it under the terms of the GNU General Public License* as published by the Free Software Foundation; either version 2* of the License, or (at your option) any later version.* * This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the* GNU General Public License for more details.* * You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*//* vim: set expandtab tabstop=4 shiftwidth=4 *//** Add header to the XML** dado un array que sera un xml, lo que * hacemos es a馻dirle la version de xml y * encapsularlo en un <d>....</d>* para decirle a flash que son un monton de* xml "peque駃tos" dentro*/function true_xml_to_flash($xml_str){    if (!empty($xml_str)) {        $ret = "<?xml version=\"1.0\"?>$xml_str";        $ret_0 = sprintf("%s%c", $ret, 0);    } else {    	$ret_0 = FALSE;    }    return ($ret_0);} /*** Create a "attributed" xml from array**/function get_xml_from_array($array, $name = ''){    // Filter arguments     if(!is_array($array)) {        return(FALSE);    }            if(empty($name)) {        if(empty($array["xml_name"])) {            throw new exception("no xml name", debug_backtrace(), $array);            return(FALSE);        } else {            $name = $array["xml_name"];            unset($array["xml_name"]);        }    }    $xml_str = "<".strtolower($name);    foreach($array as $key=>$element) {        if(!empty($key)) {	        $xml_str.= " ".strtolower($key)."=\"".$element."\"";        }    }    $xml_str.= "/>";    return($xml_str);}/*** return node value from a xml (format array)**/function get_xml_node_from_array($array, $node){    foreach($array as $key=>$element) {    	if ($key == $node) {	        return($element);	    }    }    return (FALSE);}/*** xml -> array**/function get_array_from_xml($xml){    // primero mirar si es de 1 nivel o de 2    // <xml a=1 b=2 c=3 />                      -> 1 nivel    // <xmlbis><xml a=1 b=2 c=3 /></xmlbis>     -> 2 niveles    if (eregi("<([a-z_]+)>(.*)</([a-z_]+)>", $xml, $xml1)) {        // es de 2 niveles        if ($xml1[1] != $xml1[3]) {            $msg= "XML attribute parser error 2[$xml]";            log_msg ($msg, "error");            echo $msg . "\n";            return(FALSE);        }        $xml_padre = $xml1[1];        $xml = trim($xml1[2]);    } else {        $xml_padre = FALSE;    }        if ($xml_padre !== FALSE) {        //TODO        /* estamos pre-procesando un xml de 2 niveles, vamos a separarlos           a ver que pasa           tendra un bucle y procesara mientras queden trozos           parecido a lo que ya se hace con los atributos        */        while (!empty($xml)) {            eregi("<([ a-z0-9,\+_:/\.@\"=]*)/>(.*)",$xml,$xml_trozo);            print_r ($xml_trozo);            $array_xml[] ="<" . $xml_trozo[1] . "/>"; // los trozos que sean, todavia no esta hecho            $xml = $xml_trozo[2];        }    } else {        $array_xml[] =$xml; // Solo hay un troxo    }    foreach ($array_xml as $xml) {        // primero vamos a sacar el nombre del array        if (!eregi("<([a-z_]+)[ ]*(.*)/>", $xml, $xml2)) {            $msg= "XML global parser error at [$xml]";            log_msg ($msg, "error");            echo $msg . "\n";            return(FALSE);        } else {            $xml_array["xml_name"] = $xml2[1];        }                $xml_atrib = trim($xml2[2]);        // ahora los parametros        while (!empty($xml_atrib)) {            if (!eregi("[ ]*([a-z_]*)[ ]*=[ ]*\"([ a-z0-9,\+_:/\.@]*)\"(.*)",$xml_atrib,$xml3)) {                $msg= "XML attribute parser error [$xml_atrib]";                log_msg ($msg, "error");                echo $msg . "\n";                return(FALSE);            } else {                $xml_array[$xml3[1]] = trim($xml3[2]);            }            $xml_atrib = trim($xml3[3]);        }    }    return($xml_array);}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -