eval
Execute strings as PHP code
The eval()
function executes a string as PHP code.
The string must be a valid PHP code and must end with a semicolon.
Note: If the string contains a return statement, it will immediately terminate the evaluation of the string.
Tip: This function can be useful when storing PHP code in a database.
Execute strings as PHP code:
<?php $string = "beautiful" ; $time = "winter" ; $str = 'This is a $string $time morning!' ; echo $str . "<br />" ; eval ( "\$str = \" $str \";" ) ; echo $str ; ?>
Output:
This is a $string $time morning! This is a beautiful winter morning!
eval ( phpcode )
parameter | describe |
---|---|
phpcode | Required. Specifies the PHP code to be calculated. |