Summary of php eval function usage
- $ 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 );
This function can substitute variable values in strings and is usually used to process database data. The code_str parameter is the string to be processed. Note: the string to be processed must conform to the PHP string format and contain a semicolon at the end. The strings processed by using this function are continued to the end of the PHP program. |