以外层为准
执行以后可以查看源代码为<?php echp 'hello,world!'; ?>

解决方案 »

  1.   

    <?php
        echo "<?php?> echo 'hello,world!'; ?>";
    echo '<br>';
        echo htmlspecialchars("<?php echo 'hello,world!'; ?>");
    ?>结果为echo 'hello,world!'; ?>
    <?php echo 'hello,world!'; ?>大家解释一下原因
      

  2.   

    1.
      echo "<?php?> echo 'hello,world!'; ?>";
      它将echo 中的<?php?>编译成html中的php脚本。
    2.
      echo htmlspecialchars("<?php echo 'hello,world!'; ?>");
      而这句话通过htmlspecialchars将<?php ?>中的东西原样输出了
      

  3.   

    浏览器显示:
    echo 'hello,world!'; ?>
    <?php echo 'hello,world!'; ?>浏览器源代码:
    <?php?> echo 'hello,world!'; ?><br>&lt;?php echo 'hello,world!'; ?&gt;不是很正常吗?
      

  4.   

    <?php
        echo "<?php echo 'hello,world1!'; ?>";
    ?>
    中的"<?php echo 'hello,world1!'; ?>"被认为是字符串,所以代码显示为:
    <?php echo 'hello,world1!'; ?>,但这其中又有<?php ?>,html无法解释,所以页面什么也显示不出来。echo "<?php?> echo 'hello,world!'; ?>";的道理也是一样的,<?php?>无法显示,只能显示出echo 'hello,world!'; ?>。而echo htmlspecialchars("<?php echo 'hello,world!'; ?>");一句,由于htmlspecialchars函数把后面的字符串"<?php echo 'hello,world!'; ?>"转化成了能被html显示的特殊格式,所以页面显示的是正常的。