game/onyx2/require/parse.php

73 lines
2.6 KiB
PHP

<?php
function parse_config($node,$name = 'var',$attribut = 'name')
{
$configs = $node->childNodes;
if($configs)
{
$array = array();
foreach($configs as $value)
{
if($value->nodeName == $name)
{
if($value->getElementsByTagName($name)->length == 0)
{
$array[$value->getAttribute($attribut)] = trim($value->textContent);
}
else $array[$value->getAttribute($attribut)] = parse_config($value,$name,$attribut);
}
}
return $array;
}
else return array();
}
/*function parse($file)
{
$xml = new DOMDocument();
$xml->load($file);
#$xml->validate();
if($root = $xml->documentElement->getAttribute('root'))
{
if($root == substr(FILE,0,strlen($root)))
{
$search = substr(FILE,strlen($root));
$paths = explode('/',$search);
$paths2 = $paths;
foreach($paths as $key => $path)
{
for($i = $key - 1; $i >= 0; $i--)
{
$paths2[$key] = $paths[$i] . '/' . $paths2[$key];
}
if($key != count($paths) - 1) $paths2[$key] .= '/';
}
foreach($xml->getElementsByTagName('config') as $value)
{
$config[$value->getAttribute('match')] = $value;
}
$parsed = array();
array_unshift($paths2,'*');
foreach($paths2 as $path)
{
if($config[$path]) $parsed = array_merge($parsed,parse_config($config[$path]));
}
return $parsed;
}
}
else return FALSE;
}
define('FILE','/var/www/site/test/test.php');
print_r(parse('../config/root.xml'));*/
?>