可将字符串之中的变量值代入,通常用在处理数据库的资料上。
函数处理后的字符串会沿续到 PHP 程序结束。
也就是说字符串中的$string变量用eval处理后再显示可以显示它的值,
例子已经很清楚了
第一个echo显示This is a $string with my $name in it. 
第二个echo显示This is a cup with my coffee in it. 
这还看不出区别吗?

解决方案 »

  1.   

    它和
    $str = "This is a $string with my $name in it.";
    echo $str;
    得到的效果一样啊。
      

  2.   

    <?php
    $str = 'This is a $string with my $name in it.';
    echo $str. "\n";$string = 'cup';
    $name = 'coffee';
    eval("\$str1 = \"$str\";");
    echo $str1. "\n";$string = 'test';
    $name = 'you';
    eval("\$str1 = \"$str\";");
    echo $str1. "\n";
    ?>
    这样是否好理解点?
      

  3.   

    就是把字符串变成可执行的PHP语句比如:
    <!-- 1 -->
    $etc = "include('wo"."kao.inc');";eval($etc);<!-- 2 -->
    include('wokao.inc');
    以上1和2是相等的
      

  4.   

    $a=1;
    echo $a;
    eval('$a=5');
    echo $a;
      

  5.   

    单引号包含的字符串中 $可以不用转义,但双引号包含的$必须转义.

    $word = "hello";
    echo "$word, world!"; //得到  hello, world!echo '$word, world!'; //得到  $word, world!
      

  6.   

    to: xuzuning(唠叨) 
    eval("\$str1 = \"$str\";");这一句和
    $str1 = "This is a $string with my $name in it.";是不是等价的?to:gaofaq(老高)
    $etc = "include('wo"."kao.inc');";
    eval($etc);
    这样就可以了吗?不用输出?eval()是不是和repuire()一样,在他出现的地方被他指定的文本替换?不知道我这样理解对不对?
      

  7.   

    php手册说的很清楚。echo也可以,但是已经输出了,如果你只是要把里面的变量替换了就要用eval