「PHP 标记种类」

内容:介绍PHP中的四种标签;

<?php ?>

<?php echo ‘if you want to serve XHTML or XML documents, do it like this’; ?>

这是最常用的,也是建议使用的格式;

<script language=”php”></script>

<script language=”php”>

echo ‘some editors (like FrontPage) don\’t like processing instructions’;

</script>

这种标签格式也是支持的。

<? echo ” ?>

<? echo ‘this is the simplest, an SGML processing instruction’; ?>
<?= expression ?> This is a shortcut for “<? echo expression ?>”

仅在通过 php.ini 配置文件中的指令 short_open_tag 打开后才可用,或者在 PHP 编译时加入了 –enable-short-tags 选项。
自 PHP 5.4 起,短格式的 echo 标记(`<?=’) 总会被识别,而不管 short_open_tag 的设置是什么,直接无视。

文档中“建议关闭”对这种标签的支持,因为在生成XML文档的时候会出现问题(XML是以 `<?’ 开始的),之所以保留是为了兼容。

<% echo ”; %>

<% echo ‘You may optionally use ASP-style tags’; %>
<%= $variable; # This is a shortcut for “<% echo . . .” %>

ASP 风格标记(上例 4)仅在通过 php.ini 配置文件中的指令 asp_tags 打开后才可用。