fehlerbehebung
This commit is contained in:
parent
a94b10ce8d
commit
8ce4ace92c
13
index.php
13
index.php
|
@ -28,8 +28,10 @@ function get_blocks($lines) {
|
|||
|
||||
$new_block = array();
|
||||
foreach ($lines as $line) {
|
||||
if($line == '')
|
||||
if($line == '') {
|
||||
$blocks[] = $new_block;
|
||||
$new_block = array();
|
||||
}
|
||||
else {
|
||||
if(str_contains($line, ':'))
|
||||
$new_block[] = explode(':', $line);
|
||||
|
@ -49,17 +51,18 @@ function generate_json($blocks) {
|
|||
$block_title = '';
|
||||
foreach($block as $item) {
|
||||
if(gettype($item) == 'array') {
|
||||
$block_json_array = array_merge($block_json_array, array($item[0] => $item[1]));
|
||||
$block_json_array[$item[0]] = $item[1];
|
||||
}
|
||||
else
|
||||
else {
|
||||
$block_title = $item;
|
||||
}
|
||||
}
|
||||
$json_array = array_merge($json_array, array($block_title => $block_json_array));
|
||||
$json_array[$block_title] = $block_json_array;
|
||||
reset($block_json_array);
|
||||
}
|
||||
return json_encode($json_array);
|
||||
}
|
||||
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
echo generate_json(get_blocks(get_lines($sensor_data)));
|
Loading…
Reference in New Issue