eval
把字符串作为PHP代码执行
eval()
函数将字符串作为 PHP 代码来执行。
该字符串必须是有效的 PHP 代码,并且必须以分号结尾。
注意:如果字符串中包含 return 语句,它将会立即终止对字符串的求值。
提示:这个函数在将 PHP 代码存储在数据库中时可能会很有用。
将字符串作为 PHP 代码执行:
<?php $string = "beautiful"; $time = "winter"; $str = 'This is a $string $time morning!'; echo $str. "<br />"; eval("\$str = \"$str\";"); echo $str; ?>
输出:
This is a $string $time morning! This is a beautiful winter morning!
eval(phpcode)
参数 | 描述 |
---|---|
phpcode | 必需。规定要计算的 PHP 代码。 |