game/onyx2/require/parse.php

70 lines
2.2 KiB
PHP
Raw Normal View History

2009-11-01 11:00:00 +00:00
<?php
function parse_config($node, $name = 'var', $attribut = 'name')
{
$configs = $node->childNodes;
if ($configs) {
$array = array();
2009-11-01 11:00:00 +00:00
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);
}
2009-11-01 11:00:00 +00:00
}
}
return $array;
} else {
return array();
2009-11-01 11:00:00 +00:00
}
}
2009-11-01 11:00:00 +00:00
/*function parse($file)
{
$xml = new DOMDocument();
2009-11-01 11:00:00 +00:00
$xml->load($file);
#$xml->validate();
2009-11-01 11:00:00 +00:00
if($root = $xml->documentElement->getAttribute('root'))
{
if($root == substr(FILE,0,strlen($root)))
{
$search = substr(FILE,strlen($root));
2009-11-01 11:00:00 +00:00
$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] .= '/';
}
2009-11-01 11:00:00 +00:00
foreach($xml->getElementsByTagName('config') as $value)
{
$config[$value->getAttribute('match')] = $value;
}
2009-11-01 11:00:00 +00:00
$parsed = array();
array_unshift($paths2,'*');
2009-11-01 11:00:00 +00:00
foreach($paths2 as $path)
{
if($config[$path]) $parsed = array_merge($parsed,parse_config($config[$path]));
}
2009-11-01 11:00:00 +00:00
return $parsed;
}
}
else return FALSE;
}
define('FILE','/var/www/site/test/test.php');
print_r(parse('../config/root.xml'));*/