PHP
- 26 ответов
- 0 вопросов
19
Вклад в тег
$files = glob("blocks/*.php");
$result = [];
foreach ($files as $filename) {
$time = \filectime($filename);
$result[$time] = $filename;
}
ksort($result);
foreach ($result as $file) {
include($file);
}
function makeArray($keys, $value) {
$result = [];
if (sizeof($keys) == 1) {
$key = $keys[0];
$result[$key] = $value;
} else {
$key = array_shift($keys);
$result[$key] = makeArray($keys, $value);
}
return $result;
}
$path = 'http://api.warface.ru/user/stat/?name=Элез&server=1';
$content = file_get_contents($path);
$content = json_decode($content, TRUE);
$fullResponse = $content['full_response'];
$fullResponse = explode("\n", $fullResponse);
$result = [];
foreach ($fullResponse as $string) {
$string = preg_split('/[\s]*=[\s]*/u', $string, -1, PREG_SPLIT_NO_EMPTY);
if ($string) {
preg_match_all('/[\s]*\[([^\[\]]+)\]([^\[\]]+)/', $string[0], $matches);
$keys = [];
$i = 1; $total = \sizeof($matches);
for ($i; $i < $total; $i+=2) {
$keys = [];
foreach ($matches[$i] as $num => $key) {
$keys[] = $key;
$keys[] = $matches[$i+1][$num];
}
$array = makeArray($keys, $string[1]);
$result = array_merge_recursive($result, makeArray($keys, $string[1]));
}
}
}
$content['full_response'] = $result;
echo '<pre>';
var_dump($content);
echo '</pre>';
function addParent($array, $parent = null) {
foreach ($array as $key => $value) {
if (\is_null($parent)) {
$array[$key]['category'] = addParent($value['category'], $value['@attributes']['code']);
$array[$key]['@attributes'] = $value['@attributes'];
} else {
$array[$key]['code_parent'] = $parent;
}
}
return $array;
}