28 lines
686 B
PHP
Executable File
28 lines
686 B
PHP
Executable File
#!/usr/bin/php
|
|
<?php # -*- coding: utf-8 mode: php -*- vim:sw=2:sts=2:et:ai:si:sta:fenc=utf-8
|
|
|
|
function fix_value($value) {
|
|
if ($value === "true") return true;
|
|
elseif ($value === "false") return false;
|
|
elseif ($value === "null") return null;
|
|
else return $value;
|
|
}
|
|
|
|
$data = array();
|
|
$empty = true;
|
|
for ($i = 1; $i < $argc; $i++) {
|
|
$namevalue = $argv[$i];
|
|
if (preg_match('/(.*?)=(.*)/', $namevalue, $ms)) {
|
|
$name = $ms[1];
|
|
$value = fix_value($ms[2]);
|
|
$data[$name] = $value;
|
|
} else {
|
|
$data[] = fix_value($namevalue);
|
|
}
|
|
$empty = false;
|
|
}
|
|
|
|
$options = JSON_NUMERIC_CHECK;
|
|
if ($empty) $options += JSON_FORCE_OBJECT;
|
|
echo json_encode($data, $options);
|