PHP的4種開始和結束標記

來源:互聯網
上載者:User

1.
<?php echo 'if you want to serve XHTML or XML documents, do 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 . . ." %>

上例中的 1 和 2 總是可用的,其中 1 是最常用,並建議使用的。

短標記(上例 3)僅在通過 php.ini 設定檔中的指令 short_open_tag 開啟後才可用,或者在 PHP 編譯時間加入了 --enable-short-tags 選項。

注: 假如用 PHP 3 還可以通過 short_tags() 函數啟用使用短標記。此方法只適用於 PHP 3!


ASP 風格標記(上例 4)僅在通過 php.ini 設定檔中的指令 asp_tags 開啟後才可用。

注: 對 ASP 風格標記的支援是 3.0.4 版添加的。

注: 在以下情況應避免使用短標記:開發需要發行的程式或者庫,或者在使用者不能控制的伺服器上開發。因為目標伺服器可能不支援短標記。為了代碼的移植及發行,確保不要使用短標記。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.