PHP 中的 eval() 函数
phpprogrammingserver side programming更新于 2025/11/15 19:35:00
eval() 函数将字符串评估为 PHP 代码。
语法
eval(code)
参数
code − 要评估的 PHP 代码。
返回
除非在代码字符串中调用 return 语句,否则 eval() 函数返回 null。然后返回传递给 return 的值。如果代码字符串中存在解析错误,则 eval() 返回 false。
示例
<?php
$one = "Demo";
$two = "text";
$res = 'This is $one $two!';
echo $res. "<br>";
eval("\$res = \"$res\";");
echo $res;
?>
输出
以下是输出。
This is $one $two! This is Demo text!

