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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -