章 6.基本句法

目錄
進入 PHP 語言模式
分隔指令
加注釋的方法

進入 PHP 語言模式

在 HTML 文件中插入 PHP 的指令共有四種方法:

示範 6-1.Ways of escaping from HTML

1.  <? echo ("this is the simplest, an SGML processing instruction\n"); ?>
 
2.  <?php echo("if you want to serve XHTML or XML documents, do like this\n"); ?>

3.  <script language="php"> 
        echo ("some editors (like FrontPage) don't
              like processing instructions");
    </script>

4.  <% echo ("You may optionally use ASP-style tags"); %>
    <%= $variable; # This is a shortcut for "<%echo .." %>

上面列出的方法中第一種只當 PHP 被設定成接受 "短標籤" 時才會有效。 設定方法可以 在調設文件 PHP.INI 中把 short_open_tag 設為真值, 或者在編譯 PHP 時執行 configure 時加入 --enable-short-tags 這個選項。

The second way is the generally preferred method, as it allows for the next generation of XHTML to be easily implemented with PHP.

第四種方法也只有當 ASP 形態的標籤 被允許時才有效。 這需要調設 asp_tags 這個參數。

備注:對 ASP-style 標籤的支援從 PHP 第 3.0.4 版開始.

程式段的結束標記將會包括跟隨在其後的換行符號。 (假如有換行符號的話。)