« 42. 字串的寫法 | (回到Blog入口) | 44. 如何定義一個函數? »

43. here doc syntax

jollen 發表於 October 27, 2006 3:51 PM

"<<<" 稱為 here doc syntax,PHP 4/5 才有提供這個語法,用來定義「一堆」字串給變數時特別好用,例如:

<?php $str = <<<EOD I saw a dog yesterday. It's very fat. Too fat to walk. I tried to help it. But in vain. Because it weights 100 KG. EOD; ?>

$str 字串的值即為:

I saw a dog yesterday. It's very fat. Too fat to walk. I tried to help it. But in vain. Because it weights 100 KG.

EOD 為字串的開始與結果,可自定,要注意的是,<<

--jollen

版權聲明

請參閱頁面底部的 CC 授權條款。此外,Jollen's PHP 專欄禁止引用、修改與轉貼,如果您想與朋友分享的話,我們只允許網站連結(hyperlink)的形式。

發表一個評論

(如果你此前從未在此 Blog 上發表過評論,則你的評論必須在 Blog 主人驗證後才能顯示,請你耐心等候。)

| Top | Jollen's Forum |
Jollen's PHP 專欄採用 Attribution-NonCommercial-NoDerivs 2.5 授權條款
Copyright(c) 2001-2007,2010 www.jollen.org