to lanxk(蓝) 没错,就是你说的这样!我的确是要从数据库中取出php 代码执行,但从数据库中取出来,就是一个变量,我不知道如何执行它,所以请教各位!
To dhlxmy():你的意思我明白,我也很关心这个问题,我一直不知道怎么解决,据我了解在phpx里有人会,但就是不愿意说出来,你算了吧。
eval -- Evaluate a string as PHP code Description mixed eval ( string code_str) eval() evaluates the string given in code_str as PHP code. Among other things, this can be useful for storing code in a database text field for later execution. There are some factors to keep in mind when using eval(). Remember that the string passed must be valid PHP code, including things like terminating statements with a semicolon so the parser doesn't die on the line after the eval(), and properly escaping things in code_str. Also remember that variables given values under eval() will retain these values in the main script afterwards. A return statement will terminate the evaluation of the string immediately. In PHP 4, eval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned. In PHP 3, eval() does not return a value. //手册中的,看关键的句子:将给定的php代码字符串执行,......这对于将PHP代码存放在数据库文本字段中供以后执行是非常有用的。。
但如果是从数据库取出来,就只是个变量,无法变成代码执行的!
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.';
echo $str. "\n";
eval("\$str = \"$str\";");
echo $str. "\n";
?>
$str就是你从数据库取出的内容
你也可以用模板,smarty
楼主想把它取出来并且执行。
但是 我不知道答案是什么
代码执行,但从数据库中取出来,就是一个变量,我不知道如何执行它,所以请教各位!
Description
mixed eval ( string code_str)
eval() evaluates the string given in code_str as PHP code. Among other things, this can be useful for storing code in a database text field for later execution. There are some factors to keep in mind when using eval(). Remember that the string passed must be valid PHP code, including things like terminating statements with a semicolon so the parser doesn't die on the line after the eval(), and properly escaping things in code_str. Also remember that variables given values under eval() will retain these values in the main script afterwards. A return statement will terminate the evaluation of the string immediately. In PHP 4, eval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned. In PHP 3, eval() does not return a value.
//手册中的,看关键的句子:将给定的php代码字符串执行,......这对于将PHP代码存放在数据库文本字段中供以后执行是非常有用的。。
非常感谢ice_berg16(寻梦的稻草人)更明确地说明了问题!谢谢大家帮助!