Home >Backend Development >PHP Tutorial >2778085001
Definition and usage
eval() function calculates string according to PHP code.
The string must be legal PHP code and must end with a semicolon.
If no return statement is called in the code string, NULL is returned. If there are parsing errors in the code, the eval() function returns false.
Syntax
?
|
参数 | 描述 |
---|---|
phpcode | 必需。规定要计算的 PHP 代码。 |
提示和注释
注释:返回语句会立即终止对字符串的计算。
注释:该函数对于在数据库文本字段中供日后计算而进行的代码存储很有用。
例子
?
|
输出:
This is a $string $time morning!This is a beautiful winter morning!
<br>eval() 函数在CodeIgniter框架里也有用到。在 /system/database/DB.php 文件中,根据系统的配置动态的定义了一个类 CI_DB,具体代码片段如下:
?
|
Parameters | Description | phpcoderequired. Specifies the PHP code to be calculated. 🎜🎜🎜🎜🎜Tips and Notes🎜🎜🎜Note: 🎜The return statement immediately terminates the evaluation of the string. 🎜🎜🎜Comments: 🎜This function is useful for storing code in a database text field for later calculations. 🎜🎜🎜Example🎜🎜🎜?🎜🎜🎜🎜🎜🎜🎜
---|