標籤:io 使用 ar 檔案 資料 sp on c 代碼
一、基本文法
(1)PHP標記
<?phpecho "Hello World!";// 當檔案為純PHP時,最好在末尾刪除PHP結束標記//?>
(2)從HTML中分離
// 在一對開始和結束之外的內容,都會被PHP解譯器忽略。也就是html標籤和PHP代碼混合的那種,跟jsp,asp一樣...<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 if ($expression == true): ?> This will show if the expression is true.<?php else: ?> Otherwise this will show.<?php endif; ?>
(3)指令分隔字元,注釋
PHP需要在每個語句後面用分隔字元結束指令。
注釋: // 或 /* ... */ 但是,*/ 會匹配最近的那個,切記!切記!
二、類型
PHP支援8種未經處理資料類型。
四種標量類型:boolean(布爾型),integer(整型),float(浮點型,double),string(字串)
兩種複合類型:array(數組),object(對象)
兩種特殊類型:resource(資源),NULL(無類型)
<?php$a_bool = TRUE; // a boolean$a_str = "foo"; // a string$a_str2 = ‘foo‘; // a string$an_int = 12; // an integerecho gettype($a_bool); // prints out: booleanecho gettype($a_str); // prints out: string// If this is an integer, increment it by fourif (is_int($an_int)) { $an_int += 4;}// If $bool is a string, print it out// (does not print out anything)if (is_string($a_bool)) { echo "String: $a_bool";}?>
(1)Boolean 布爾類型
三日php之路 -- 第一天(php語言參考)