PHP eval() 函数 危险函数

定义和用法

eval() 函数把字符串按照 PHP 代码来计算。

该字符串必须是合法的 PHP 代码,且必须以分号结尾。

如果没有在代码字符串中调用 return 语句,则返回 NULL。如果代码中存在解析错误,则 eval() 函数返回 false。

语法

eval(phpcode)
<?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! 

 

posted @ 2018-01-05 13:46  lei12138  阅读(447)  评论(0编辑  收藏  举报