mixed eval ( string
You can execute the contents of a string as if it were PHP code using the
function. This takes just one string parameter and executes that string as PHP. For example:
$str = '$i = 1; print $i;'; eval($str);
That script assigns two PHP statements to
$str, then passes
eval() for execution.
eval() function allows you to store your PHP code in a database, or to build it at runtime, which gives you a lot more flexibility.
If you are considering using
eval(), bear in mind these words from the creator of PHP, Rasmus Lerdorf: “If
eval() is the answer, you’re almost certainly asking the wrong question.” That is, you should be able to achieve your goals without resorting to