php裡單引和雙引的用法區別和串連符(.)

來源:互聯網
上載者:User

標籤:last   first   簡寫   tar   單引號   www   解釋   ble   ring   


" "雙引號裡面的欄位會經過編譯器解釋,然後再當作HTML代碼輸出。
‘ ‘單引號裡面的不進行解釋,直接輸出。
例如:
$abc=‘my name is tome‘;
echo $abc //結果是:my name is tom
echo ‘$abc‘ //結果是:$abc
echo "$abc" //結果是:my name is tom

一、引號定義字串
在PHP中,通常一個字串被定義在一對引號中(這裡是一樣的效果),如:
‘I am a string‘
"I am a string"

二、字串的串連(.)
字串可以使用字串聯接符(.)來串連,如:
$first_name = ‘a‘;
$last_name = ‘b‘;
$full_name = $first_name . $last_name;

常見的用途是建立大塊的HTML字串代碼,賦值號 (=) 串連符 (.) 可以被簡寫合并為 (.=) 符
號,如:
$html = ‘<table>‘;
$html .= ‘<tr><td>number</td><td>s</td></tr>‘;
for ( $i=0 ; $i<10 ; $i++) {
$s = $i * $i;
$html .= ‘<tr><td>‘ . $i . ‘</td><td>‘ . $s . ‘</td></tr>‘;
}
$html .= ‘</table>‘;

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.