Eval -- Evaluate a string as PHP code
Description
Mixed eval (string code_str)
Eval () evaluates the string given in code_str as PHP code. Among other things, this can be useful for storing code in a database text field for later execution.
There are some factors to keep in mind when using eval (). remember that the string passed must be valid PHP code, including things like terminating statements with a semicolon so the parser doesn't die on the line after the eval (), and properly escaping things in code_str.
Also remember that variables given values under eval () will retain these values in the main script afterwards.
A return statement will terminate the evaluation of the string immediately. in PHP 4, eval () returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned. in PHP 3, eval () does not return a value.
Example 1. eval () example-simple text merge
$ String = 'cup ';
$ Name = 'coffee ';
$ Str = 'This is a $ string with my $ name in it. http://www.7di.net ';
Echo $ str. "\ n ";
Eval ("\ $ str = \" $ str \";");
Echo $ str. "\ n ";
?>;
The above example will show:
This is a $ string with my $ name in it.
This is a cup with my coffee in it.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service