1. 以下形式都是正确的
<? echo 'hello'; ?> //如果发现不能使用,需要设置 short_open_tag php.ini
<? echo 'hello'; //也就是说可以没有?>,但是不能跟html混合
当然也可以通过设置php.ini , 使用以下的形式
2. <script language="php">
echo 'some editors (like FrontPage) don/'t
like processing instructions' ;
</script>
3. <? echo 'this is the simplest, an SGML processing instruction' ; ?>
<?= expression ?> This is a shortcut for "<? echo expression ?> "
4. <% echo 'You may optionally use ASP-style tags'; %>
<%= $variable; # This is a shortcut for "<% echo . . ." %>
实践:
1. //或者#注释对?>并不起作用, 如以下代码
// $file_contents = '<?php die(); ?> ' . "/n";
2. <?php这个后面需要有空格,但是<?或<%后面并不需要空格
3. 当使用<?时,注意以下代码,因为<?会以为是php代码开始
<?xml version="1.0"?>
4. 注释正则的时候,小心
/*
$f->setPattern('/^/d.*/ );
*/
读者测试:echo 的时候带有?>, 请测试下面的代码
<?php echo '<?xml version="1.0" ? >' ?>