其实eval语句的执行与echo的执行原理是一样的。
楼主的问题可以简化成:
把eval("\$str = \"$str\";");改成echo("\$str = \"$str\";");,你得到的字符串就是eval要执行的PHP语句。

解决方案 »

  1.   

    $string = 'cup'; 
    $name = 'coffee'; 
    $str = ”This is a $string with my $name in it.“;
    echo $str;
    上边的程序也可打印出This is a cup with my coffee in it.
    双引号中的变量,输出会自动转化它的值,单引则相反!
    上边的程序是一个道理!
    变一下就是这样:
    $string = 'cup'; 
    $name = 'coffee'; 
    $str = "This is a $string with my $name in it."
    echo $str. "\n"; 
    $str="$str"; 
    echo $str. "\n";