regex - PHP preg_replace - How to get the same result without `/e` `eval` - improved security and speed performance? -
how same result without /e
eval
- improved security , speed performance?
function finclude($file){ return include($file); } $str = "today {include 'date.php'}."; echo preg_replace("/\{include '(.*)\'}/e", 'finclude("$1")', $str);
date.php:
<?php return date('js \of f'); ?>, 2011
result: today 20th of july.
you can use preg_replace_callback
echo preg_replace_callback("/\{include '(.*)\'}/", function($m) { return include($m[1]); }, $str);
Comments
Post a Comment