
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 1.21 KB | hits: 11 | expires: Never
<?php
$file = fopen($argv[1], "r");
$json = "";
$depth = 0;
while (!feof($file)) {
$chr = fgetc($file);
switch ($state) {
case 0:
echo $chr;
if ($chr == '=' || $chr == '(' || $chr == ',') {
$state = 1;
}
break;
case 1:
if ($chr == '[' || $chr == '{') {
$json .= $chr;
$depth = 1;
$state = 2;
} else if (preg_match("/\s/", $chr)) {
echo $chr;
} else {
echo $chr;
$state = 0;
}
break;
case 2:
$json .= $chr;
if ($chr == '[' || $chr == '{') {
$depth++;
} else if ($chr == ']' || $chr == '}') {
$depth--;
}
if ($depth == 0) {
$code = var_export(json_decode($json), true);
$code = str_replace("stdClass::__set_state", "", $code);
echo $code;
$json = "";
$state = 0;
}
break;
}
}
?>