Current Location: Home> Function Categories> eval

eval

Execute strings as PHP code
Name:eval
Category:Miscellaneous
Programming Language:php
One-line Description:Calculate the string according to PHP code.

Definition and usage

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.

Example

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!

grammar

 eval ( phpcode )
parameter describe
phpcode Required. Specifies the PHP code to be calculated.
Similar Functions
Popular Articles