php eval()

2025-01-02 07:44:35
推荐回答(2个)
回答1:

你这样理解

括号里$前面加入\是为了“转译”,这样的话$str就不会变成真实的字符串

eval ("\$str = \"$str\";"); 等同于 $str = "This is a $string with my $name in it.
"; 等同于 $str = "This is a cup with my coffee in it.
";

回答2:

单引号里面的内容原样输出;

输出双引号里面的内容时会查找其中是否有变量,用相应的值代替。