PHPeval () function, phpeval function. PHPeval () function, phpeval function definition and usage eval () function calculate the string according to PHP code. The string must be a valid PHP code and must end with a semicolon. If PHP eval () function, phpeval function
Definition and usage
The eval () function calculates the string according to the PHP code.
The string must be a valid PHP code and must end with a semicolon.
If the return statement is not called in the code string, NULL is returned. If a parsing error exists in the code, the eval () function returns false.
Syntax?
Parameters |
Description |
Phpcode |
Required. Specifies the PHP code to be calculated. |
Tips and comments
Note: The Return statement immediately terminates string calculation.
Note: This function is useful for storing code in database text fields for future computation.
Example?
$string = "beautiful" ; $time = "winter" ; $str = 'This is a $string $time morning!' ; echo $str . " " ; eval ( "\$str = \"$str\";" ); echo $str ; ?> |
Output:
This is a $ string $ time morning! This is a beautiful winter morning!
The eval () function is also useful in the CodeIgniter framework. In the/system/database/DB. php file, a class CI_DB is dynamically defined according to the system configuration. the specific code snippet is as follows:
?
if ( ! isset( $active_record ) OR $active_record == TRUE) { require_once (BASEPATH. 'database/DB_active_rec.php' ); if ( ! class_exists ( 'CI_DB' )) { eval ( 'class CI_DB extends CI_DB_active_record { }' ); } } else { if ( ! class_exists ( 'CI_DB' )) { eval ( 'class CI_DB extends CI_DB_driver { }' ); } } require_once (BASEPATH. 'database/drivers/' . $params [ 'dbdriver' ]. '/' . $params [ 'dbdriver' ]. '_driver.php' ); // Instantiate the DB adapter $driver = 'CI_DB_' . $params [ 'dbdriver' ]. '_driver' ; $DB = new $driver ( $params ); |
Http://www.bkjia.com/PHPjc/1135472.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1135472.htmlTechArticlePHP eval () function, phpeval function definition and usage eval () function calculates the string according to PHP code. The string must be a valid PHP code and must end with a semicolon. If...