web後端 - 關於php中嵌入html代碼時結束符“?>”位置為什麼這樣放置?

來源:互聯網
上載者:User
大家好,本人初學php,關於html和php代碼嵌入有點不明白,

舉個例子:

There were some problems with the form you submitted.Please complete the fields highlighted below and click Send Details to resend the form.

Thanks for choosing to join The Widget Club. To register, please fillin your details below and click Send Details. Fields marked with an asterisk(*) are required.

為什麼這裡遇到“}”就把它單獨放置在中。為什麼不能寫成這樣?

There were some problems with the form you submitted.Please complete the fields highlighted below and click Send Details to resend the form.

} else {

Thanks for choosing to join The Widget Club. To register, please fillin your details below and click Send Details. Fields marked with an asterisk(*) are required.

}

非常感謝,解疑答惑!

回複內容:

大家好,本人初學php,關於html和php代碼嵌入有點不明白,

舉個例子:

There were some problems with the form you submitted.Please complete the fields highlighted below and click Send Details to resend the form.

Thanks for choosing to join The Widget Club. To register, please fillin your details below and click Send Details. Fields marked with an asterisk(*) are required.

為什麼這裡遇到“}”就把它單獨放置在中。為什麼不能寫成這樣?

There were some problems with the form you submitted.Please complete the fields highlighted below and click Send Details to resend the form.

} else {

Thanks for choosing to join The Widget Club. To register, please fillin your details below and click Send Details. Fields marked with an asterisk(*) are required.

}

非常感謝,解疑答惑!

因為

標籤屬於html而不是php語言,所以不能加到php起止符號內


表示他為php的 代碼塊結束符號“}”

因為

There were some problems with the form you submitted.Please complete the fields highlighted below and click Send Details to resend the form.

不是合法的PHP代碼.

  1. 在中的是php代碼,第二種寫法,很明顯標籤

    中的內容不是php代碼。

  2. 如果想要用第二種寫法,可以這樣寫:

 ... 

'; } else { echo '

...

'; } ?>

所有的非html代碼都要嵌入在內,而所有在裡面的都會被解析為php代碼,按照你的想法,那一對

標籤裡的內容不屬於php代碼,所以應該是這樣分段嵌入的:

xxxxxx

7048
其實應該這樣理解
在php裡, ?> 表示開始輸出html,

可以這樣:

    

There were some problems with the ....

Thanks for choosing to join The Widget Club....

語言PHP的文法起始標籤就是 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.