<?php
$str = ' echo ', ' hello ';
$content = eval ($str);
Echo ', word! ‘;
?>
Execution Result: hello,word!
First, the string as a PHP script processing. Believe this, we all know!
<?php
$str = ' Hello, world! echo "Hello,";
$content = eval ($str);
Echo ' word! ';
Execution Result:
/*
Parse error:syntax error, unexpected ' echo ' (T_echo) in E:\web\www\swoole_test\eval.php (4): eval () ' D code on line 1 word !
*/
?>
Second, when there is illegal PHP code in the string, error. I believe we all know it!
<?php
$str = ' Hello, world! echo "Hello,";
$content = eval ('?> '. $str); Note that the eval is now in Riga "? > "string
Echo ' word! ';
Execution Result:
/*
Hello, world! echo "Hello,"; word!
*/
?>
Three, at this time, there are illegal PHP code inside the string, but, no error.
---because the prefix "?>" (PHP Terminator), it has the following "string" All as a "string", right!
On the basis of (c), embedded in the string <?php ...? The > module is equivalent to embedding PHP code in an HTML file. What would it be like?
<?php
$str = ' Hello, world! <?php echo "Hello,";?> ';
$content = eval ('?> '. $str);
Echo ' word! ';
Execution Result:
/*
Hello, world! hello,word!
*/
?>
Ok! It will recognize the PHP module in the "string" and execute it!
The above example illustrates the role of eval ('?> ' $str) and eval ($STR).
In fact, the eval ($str) $str inside,
If the string contains a <?php ...? >,
Then the $STR string must be in <?php ...? > Precede with "?>" PHP Terminator.
Eval () An interesting php function