Sunday, 21 October 2018

Custom parsing function PHP

I'm trying to remove eval from the following function. I tried with sprintf and ${} , but still cannot find a solution.

Here the function:

function parseDbString(string $value = 'Looking for a good '){
    $pippo='Pizza';
    return preg_replace_callback('//', function($res) use ($pippo) {
      // $val=${trim($res[1])}; Returns "Undefined variable: $pippo"
      $val=@eval("return ".trim($res[1]).";"); // Returns "Looking for a good Pizza"
      return isset($val) ? $val : $res[0];
    },$value);
}



from Custom parsing function PHP

No comments:

Post a Comment