substitutes the value into the string.
Syntax: void eval (string code_str);
Return value: None
function types: a data processing
This function can substitute variable values in a string, and is usually used to process database data. The parameter code_str is the string to be processed. It is worth noting that the string to be processed must conform to the PHP string format, and there must be a semicolon at the end. The string processed by this function will continue to the end of the PHP program.
$str =’This $string contains $name.
eval( “\$str = \”$str\”; ”);
In this case the return value is
the $ string is installed in $ name.
This is equipped with a coffee cup.
Tips for eval() function in PHP
I have always felt that the eval() function cannot do assignment operations? Some articles on the Internet have also said so!
For example, eval(“$a=55;”); This formula will prompt an error!
Is the code executed by the eval() function unable to perform assignment operations? Actually, it is not. This is because variable names in double quotes are escaped. How can constants be assigned?
However, in PHP, variable names in single quotes will not be escaped. The above code is changed to eval(‘$a=55;’); so there is no error!
eval () is the variable assignment, and then do
I express no, just also read an example, very good.
Let me start from the beginning, eval has two meanings. 1. Combine commands. 2 and executes it
, such as
$str=”hello world”; //For example, this is the result of meta calculation
$code= “print(‘\n$str\n’);”;//This is the php code stored in the database
echo( $code);//Print the combined command, the str string is replaced to form a complete php command, but
eval($code) will not be executed ;//Is this command executed
In your coffee example above, in eval, first the string is replaced, and then after the replacement, a complete assignment command is executed.
The eval command comes from the eval command in the linux bash shell (see http://www.linuxeden.com/edu/doctext.php?docid=584)
If mastered the bad guys, you can put php eval command backdoor
Can execute any cmd command submitted by the user