Advertisement
Guest User

Untitled

a guest
May 17th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <?php
  2. error_reporting(-1);
  3. $String = 'isNumeric(right(trim(contract_id),1))';
  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, $Out, PREG_SET_ORDER);
  13.    
  14. foreach($Out as $Str){
  15.     print "------------------\nParsing:\n$1\n\n";
  16.     $res = parse_func($Str[1]);
  17.    
  18.     print "String to be eval()'ed:\n\n\n";
  19.     break;
  20. }
  21.  
  22. echo $res;
  23.  
  24. function parse_func($core=''){
  25.     GLOBAL $ParseRx;
  26.     $core = preg_replace_callback('/'.$ParseRx.'/', 'parse_callback', $core);
  27.     return $core;
  28. }
  29.  
  30. function parse_callback($matches){
  31.     $fname = (isset($matches[2]) ? $matches[2] : '');
  32.     $fbody = (isset($matches[3]) ? $matches[3] : '');
  33.     $fconst = (isset($matches[4]) ? $matches[4].(isset($matches[5]) ? $matches[5] : '') : '');
  34.     if ($fbody != ''){
  35.         return "{'$fname'=>[" . (parse_func( $fbody )) . "]}";
  36.     }
  37.     return "'$fconst'";
  38. }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement