Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(-1);
- $String = 'isNumeric(right(trim(contract_id),1))';
- $func = '\w+';
- $const = '[\w*&^+-]+';
- $wspconst = '[\w*&^+\s-]+';
- $GetRx = '\s*((?:\s*('.$func.')\s*[(](?:(?>(?:(?!\s*'.$func.'\s*[(]|[)]).)+)|(?1))*[)]))';
- $ParseRx = '((?:\s*('.$func.')\s*[(]((?: (?>(?:(?!\s*'.$func.'\s*[(]|[)]).)+)|(?1))*)[)]|\s*["\']('.$wspconst.')["\']\s*|\s*('.$const.')\s*|(?<=,)|(?<=^)(?!\s*$)))';
- preg_match_all('/'.$GetRx.'/', $String, $Out, PREG_SET_ORDER);
- foreach($Out as $Str){
- print "------------------\nParsing:\n$1\n\n";
- $res = parse_func($Str[1]);
- print "String to be eval()'ed:\n\n\n";
- break;
- }
- echo $res;
- function parse_func($core=''){
- GLOBAL $ParseRx;
- $core = preg_replace_callback('/'.$ParseRx.'/', 'parse_callback', $core);
- return $core;
- }
- function parse_callback($matches){
- $fname = (isset($matches[2]) ? $matches[2] : '');
- $fbody = (isset($matches[3]) ? $matches[3] : '');
- $fconst = (isset($matches[4]) ? $matches[4].(isset($matches[5]) ? $matches[5] : '') : '');
- if ($fbody != ''){
- return "{'$fname'=>[" . (parse_func( $fbody )) . "]}";
- }
- return "'$fconst'";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement