1. <?php echo 'if you want to serve XHTML or XML documents, do it like this'; ?>
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 . . ." %>
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 和 2 中使用的標記總是可用的,其中示例 1 中是最常用,並建議使用的。
短標記(上例 3)僅在通過 php.ini 配置文件中的指令 short_open_tag 打開后才可用,或者在 PHP 編譯時加入了 --enable-short-tags 選項。
ASP 風格標記(上例 4)僅在通過 php.ini 配置文件中的指令 asp_tags 打開后才可用。