This article introduces several examples of eval functions in php. For more information, see. In php, the eval function is used to place values into strings. Syntax: void eval (string code_str); return value: no function type: Description of data processing content 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 using this function are continued until the end of the PHP program. Example:
'; Echo $ str; eval ("/$ str =/" $ str/";"); echo $ str;?> Return value: $ name is included in $ string, and coffee is included in the Cup. Appendix: eval 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. The eval (phpcode) parameter description is required for phpcode. Specifies the PHP code to be calculated. Prompt and comment: The Return statement immediately terminates string calculation. Note: This function is useful for storing code in database text fields for future computation. Example:
"; 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. Example:
The above code can be used to substitute variable values in strings for processing database data. The code_str parameter is the string to be processed. Note that the string to be processed must conform to the PHP string format and contain a semicolon at the end. The strings processed using this function are continued until the end of the PHP program. |