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, j( ) ," ", bob, george(five(four, two))))';
- $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, $Results, PREG_SET_ORDER);
- foreach($Results as $Res){
- $FinalRes = parse_func($Res[1]);
- break;
- }
- if(isset($FinalRes)){
- print_r(json_decode($FinalRes));
- }
- function parse_func($String=''){
- GLOBAL $ParseRx;
- if($String == ''){
- return '';
- }
- $String = preg_replace_callback('/'.$ParseRx.'/', 'parse_callback', $String);
- return $String;
- }
- 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