Pulkit Gaur

dream - do - deserve

PHP Eval

Filed under: PHP at 05:36:19 On 2006-05-07

Well ,this is a slower method (100 times slower sometimes) than direct page rendering.

But ,u get total control over the pagecontent dynamically.

Many a times its safe also to secure your PHP code.The immediate application which i could think of after looking at this function is my own template engine.


function eval_new_helper($arr){
return ("echo stripslashes(\"".addslashes($arr[1])."\");");
}

function eval_new($string){
$string = "".$string."";
$string = preg_replace("/<\?=\s+(.*?)\s+\?>/", "", $string);
$string = str_replace('?>', '', str_replace( array('((.|\n)*?)<\?/","eval_new_helper",$string) ) );
return eval($string);
}

// call it from here
eval_new($string);

?>

Leave a Comment

Required

Required, hidden