Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 1.21 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. $file = fopen($argv[1], "r");
  4. $json = "";
  5. $depth = 0;
  6.  
  7. while (!feof($file)) {
  8.     $chr = fgetc($file);
  9.    
  10.     switch ($state) {
  11.         case 0:
  12.             echo $chr;
  13.        
  14.             if ($chr == '=' || $chr == '(' || $chr == ',') {
  15.                 $state = 1;
  16.             }
  17.             break;
  18.            
  19.         case 1:
  20.             if ($chr == '[' || $chr == '{') {
  21.                 $json .= $chr;
  22.                
  23.                 $depth = 1;
  24.                 $state = 2;
  25.             } else if (preg_match("/\s/", $chr)) {
  26.                 echo $chr;
  27.             } else {
  28.                 echo $chr;
  29.                 $state = 0;
  30.             }
  31.             break;
  32.            
  33.         case 2:
  34.             $json .= $chr;
  35.        
  36.             if ($chr == '[' || $chr == '{') {
  37.                 $depth++;
  38.             } else if ($chr == ']' || $chr == '}') {
  39.                 $depth--;
  40.             }
  41.            
  42.             if ($depth == 0) {
  43.                 $code = var_export(json_decode($json), true);
  44.                 $code = str_replace("stdClass::__set_state", "", $code);
  45.                 echo $code;
  46.                
  47.                 $json = "";
  48.                 $state = 0;
  49.             }
  50.            
  51.             break;
  52.     }
  53. }
  54.  
  55. ?>