Advertisement
Guest User

Untitled

a guest
May 17th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <?php
  2. error_reporting(-1);
  3. $String = 'isNumeric(right(trim ( ,contract_id,),-1, j( ) ,"  ", bob, george(five(four, two))))';
  4.  
  5. $func      = '\w+';
  6. $const     = '[\w*&^+-]+';
  7. $wspconst  = '[\w*&^+\s-]+';
  8.  
  9. $GetRx = '\s*((?:\s*('.$func.')\s*[(](?:(?>(?:(?!\s*'.$func.'\s*[(]|[)]).)+)|(?1))*[)]))';
  10. $ParseRx = '((?:\s*('.$func.')\s*[(]((?:(?>(?:(?!\s*'.$func.'\s*[(]|[)]).)+)|(?1))*)[)]|\s*["\']('.$wspconst.')["\']\s*|\s*('.$const.')\s*|(?<=,)|(?<=^)(?!\s*$)))';
  11.  
  12. preg_match_all('/'.$GetRx.'/', $String, $Results, PREG_SET_ORDER);
  13.    
  14. foreach($Results as $Res){
  15.     $FinalRes = parse_func($Res[1]);
  16.     break;
  17. }
  18.  
  19. if(isset($FinalRes)){
  20.     print_r(json_decode($FinalRes));
  21. }
  22.  
  23.  
  24. function parse_func($String=''){
  25.     GLOBAL $ParseRx;
  26.    
  27.     if($String == ''){
  28.         return '';
  29.     }
  30.    
  31.     $String = preg_replace_callback('/'.$ParseRx.'/', 'parse_callback', $String);
  32.     return $String;
  33. }
  34.  
  35. function parse_callback($Matches){
  36.     $fName = (isset($Matches[2]) ? $Matches[2] : '');
  37.     $fBody = (isset($Matches[3]) ? $Matches[3] : '');
  38.     $fConst = (isset($Matches[4]) ? $Matches[4] : '').(isset($Matches[5]) ? $Matches[5] : '');
  39.    
  40.     if($fBody != ''){
  41.         return '{"'.$fName.'": ['.(parse_func($fBody)).']}';
  42.     }
  43.    
  44.     return '"'.$fConst.'"';
  45. }
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement