fork download
  1. <?php
  2. $String = 'isNumeric(right(trim ( ,contract_id,),-1, j( ) ," ", bob, george(five(four, two))))';
  3.  
  4. $func = '\w+';
  5. $const = '[\w*&^+-]+';
  6. $wspconst = '[\w*&^+\s-]+';
  7.  
  8. $GetRx = '\s*((?:\s*('.$func.')\s*[(](?:(?>(?:(?!\s*'.$func.'\s*[(]|[)]).)+)|(?1))*[)]))';
  9. $ParseRx = '((?:\s*('.$func.')\s*[(]((?:(?>(?:(?!\s*'.$func.'\s*[(]|[)]).)+)|(?1))*)[)]|\s*["\']('.$wspconst.')["\']\s*|\s*('.$const.')\s*|(?<=,)|(?<=^)(?!\s*$)))';
  10.  
  11. preg_match_all('/'.$GetRx.'/', $String, $Results, PREG_SET_ORDER);
  12.  
  13. // test
  14.  
  15. $tmp = "
  16. \$arytmp = array(
  17. 1 => array(
  18. 'English' => array(
  19. 'One',
  20. 'January'
  21. ),
  22. 'French' => array(
  23. 'Une',
  24. 'Janvier'
  25. )
  26. )
  27. );
  28. ";
  29.  
  30. $arytmp = array(
  31. 1 => array(
  32. 'English' => array(
  33. 'One',
  34. 'January'
  35. ),
  36. 'French' => array(
  37. 'Une',
  38. 'Janvier'
  39. )
  40. )
  41. );
  42.  
  43.  
  44. // l( $tmp );
  45. print_r( "this is array\n".$arytmp."\n\n" );
  46.  
  47.  
  48. /////////////
  49.  
  50.  
  51.  
  52. foreach($Results as $Res){
  53. $FinalRes = parse_func($Res[1]);
  54.  
  55. print_r($FinalRes);
  56.  
  57. break;
  58. }
  59.  
  60. if(isset($FinalRes)){
  61. print_r(json_decode($FinalRes));
  62. }
  63.  
  64.  
  65. function parse_func($String=''){
  66. GLOBAL $ParseRx;
  67.  
  68. if($String == ''){
  69. return '';
  70. }
  71.  
  72. $String = preg_replace_callback('/'.$ParseRx.'/', 'parse_callback', $String);
  73. return $String;
  74. }
  75.  
  76. function parse_callback($Matches){
  77. $fName = (isset($Matches[2]) ? $Matches[2] : '');
  78. $fBody = (isset($Matches[3]) ? $Matches[3] : '');
  79. $fConst = (isset($Matches[4]) ? $Matches[4] : '').(isset($Matches[5]) ? $Matches[5] : '');
  80.  
  81. if($fBody != ''){
  82. return '{"'.$fName.'": ['.(parse_func($fBody)).']}';
  83. }
  84.  
  85. return '"'.$fConst.'"';
  86. }
  87. ?>
  88.  
  89.  
Runtime error #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
this is array
Array

{"isNumeric": [{"right": [{"trim": ["" ,"contract_id",""]},"-1",{"j": [ ]} ,"  ","bob",{"george": [{"five": ["four","two"]}]}]}]}
Fatal error: Call to undefined function json_decode() in /home/cU8cbt/prog.php on line 62