從HTML中分離PHP, 在HTML種寫PHP代碼

來源:互聯網
上載者:User

標籤:row   style   建議   不同的   ssi   browser   方式   必須   res   

既有PHP代碼又有HTML代碼的檔案必須以" .php "結尾.

為了使php解譯器忽略HTML代碼, php只處理一對PHP開始和結束標記之間的內容.

如:

<p>This is going to be ignored by PHP and displayed by the browser.</p><?php echo ‘While this is going to be parsed.‘; ?><p>This will also be ignored by PHP and displayed by the browser.</p>

當php遇到"<?php"標記的時候開始解析, 遇到“ ?> ”的時候結束解析. 而其他的代碼則保持原樣.

這種情況只有一個php開始以及結束標記,  如果有多組php標記,  那麼為於兩組php標記之間的代碼是否會保持原呢?

如:

<?php if ($expression == true): ?>  This will show if the expression is true.<?php else: ?>  Otherwise this will show.<?php endif; ?>

上述代碼只會輸出" This will show if expression is true "或者 “ Otherwise this will show ”中的一個, 而另一個則會被忽略.  可以看輸出PHP將會自動跳過條件陳述式中未達成的段落.

 

PHP種開始和結束標誌四種不同的寫法:

1  <?php    ?>

2  <script language="php">  </script>

3  <?  ?>

4  <%  %>

其中1、2兩種方式總是可以使用的.

方式3為區段標記,   方法4為ASP風格,   使用時必須在php.ini種配置

short_oepn_tag= true 支援識別短標記      、

asp_tags=true 支援識別ASP風格的標記

一般為了保持代碼的可移植性建議使用方式1或者2.

從HTML中分離PHP, 在HTML種寫PHP代碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.