39 lines
858 B
PHP
Executable File
39 lines
858 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
|
|
|
|
if ($argc <= 1) die("ERROR: Vous devez spécifier le nom de la clé\n");
|
|
|
|
$argindex = 1;
|
|
$arg = $argv[1];
|
|
$sep = "\t";
|
|
if ($arg == "-s") {
|
|
$sep = $argv[2];
|
|
$argindex += 2;
|
|
} elseif (substr($arg, 0, 2) == "-s") {
|
|
$sep = substr($arg, 2);
|
|
$argindex++;
|
|
}
|
|
|
|
$datum = json_decode(stream_get_contents(STDIN), true);
|
|
|
|
$first = true;
|
|
for ($i = $argindex; $i < $argc; $i++) {
|
|
$result = $datum;
|
|
$keys = explode(".", trim($argv[$i]));
|
|
foreach ($keys as $key) {
|
|
if ($result === null) break;
|
|
if ($key === "") continue;
|
|
if (isset($result[$key])) {
|
|
$result = $result[$key];
|
|
} else {
|
|
$result = null;
|
|
}
|
|
}
|
|
|
|
if ($first) $first = false;
|
|
else echo $sep;
|
|
if (is_array($result)) var_export($result);
|
|
else echo $result;
|
|
}
|
|
echo "\n";
|