PHP eval () function
Examples
The string as PHP code to calculate:
<?php
$string = "beautiful";
$time = "winter";
$str = 'This is a $string $time morning!';
echo $str. "<br>";
eval("$str = "$str";");
echo $str;
?>
$string = "beautiful";
$time = "winter";
$str = 'This is a $string $time morning!';
echo $str. "<br>";
eval("$str = "$str";");
echo $str;
?>
The output of the code above will be:
This is a $string $time morning!
This is a beautiful winter morning!
This is a beautiful winter morning!
Definition and Usage
eval () function to string calculated in accordance with the PHP code.
The string must be valid PHP code, and must end with a semicolon.
Note: return statement will terminate the calculation of the string.
Tip: This function code is stored in the database for the calculation for future text field and carried out useful.
grammar
eval( phpcode )
参数 | 描述 |
---|---|
phpcode | 必需。规定要计算的 PHP 代码。 |
technical details
return value: | Unless you call return statements in the code string, the return value passed to return statement, otherwise it returns NULL. If there is an error code string parsing, the eval () function returns FALSE. |
---|---|
PHP version: | 4+ |
PHP Misc Reference Manual