Add php files
This commit is contained in:
86
include/ECM/open_flash_chart2/php-ofc-library/json_format.php
Executable file
86
include/ECM/open_flash_chart2/php-ofc-library/json_format.php
Executable file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
// Pretty print some JSON
|
||||
function json_format($json)
|
||||
{
|
||||
$tab = " ";
|
||||
$new_json = "";
|
||||
$indent_level = 0;
|
||||
$in_string = false;
|
||||
|
||||
/*
|
||||
commented out by monk.e.boy 22nd May '08
|
||||
because my web server is PHP4, and
|
||||
json_* are PHP5 functions...
|
||||
|
||||
$json_obj = json_decode($json);
|
||||
|
||||
if($json_obj === false)
|
||||
return false;
|
||||
|
||||
$json = json_encode($json_obj);
|
||||
*/
|
||||
$len = strlen($json);
|
||||
|
||||
for($c = 0; $c < $len; $c++)
|
||||
{
|
||||
$char = $json[$c];
|
||||
switch($char)
|
||||
{
|
||||
case '{':
|
||||
case '[':
|
||||
if(!$in_string)
|
||||
{
|
||||
$new_json .= $char . "\n" . str_repeat($tab, $indent_level+1);
|
||||
$indent_level++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$new_json .= $char;
|
||||
}
|
||||
break;
|
||||
case '}':
|
||||
case ']':
|
||||
if(!$in_string)
|
||||
{
|
||||
$indent_level--;
|
||||
$new_json .= "\n" . str_repeat($tab, $indent_level) . $char;
|
||||
}
|
||||
else
|
||||
{
|
||||
$new_json .= $char;
|
||||
}
|
||||
break;
|
||||
case ',':
|
||||
if(!$in_string)
|
||||
{
|
||||
$new_json .= ",\n" . str_repeat($tab, $indent_level);
|
||||
}
|
||||
else
|
||||
{
|
||||
$new_json .= $char;
|
||||
}
|
||||
break;
|
||||
case ':':
|
||||
if(!$in_string)
|
||||
{
|
||||
$new_json .= ": ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$new_json .= $char;
|
||||
}
|
||||
break;
|
||||
case '"':
|
||||
if($c > 0 && $json[$c-1] != '\\')
|
||||
{
|
||||
$in_string = !$in_string;
|
||||
}
|
||||
default:
|
||||
$new_json .= $char;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $new_json;
|
||||
}
|
||||
Reference in New Issue
Block a user