PHP — 基礎文法

來源:互聯網
上載者:User

標籤:使用   注意   分離   結束   檔案   多行注釋   file   賦值   php注釋   

一、PHP 標記

當解析一個檔案時,PHP 會尋找起始和結束標記,也就是<?php和?>,在標記外的部分會被解析器忽略。

注意

開始標記後面必須跟上一個空白符,否則就會出錯。

二、從 HTML 中分離

凡是在PHP開始和結束標記之外的內容,都會被PHP解析器忽略。例外是使用控制語句時:

<?php $expression = TRUE; ?><?php if ($expression == true): ?> This will show if the expression is true.<?php else: ?> Otherwise this will show.<?php endif; ?><!-- 輸出為:This will show if the expression is true. -->
三、指令符分隔

使用分號分隔語句,最後一條語句的分號可以省略。

四、注釋

PHP注釋有3種類型:

// 單行注釋# 單行注釋/* 多行注釋*/
  • 多行注釋的內容從/*開始,至*/結束,因此多行注釋不能嵌套。

  • 單行注釋的內容從//或#開始,至行末結束,或者遇到?>則提前退出php解析。有時候這會導致一些問題:

  <?php    $file_contents = ‘<?php die(); ?>‘; ?> <!-- 正確將字串`‘<?php die(); ?>‘`賦值給`$file_contents` --> <?php // $file-contents = ‘<?php die(); ?>‘; ?> <!-- 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.