看板 PHP 關於我們 聯絡資訊
<?php header("Content-Type:text/html;charset=utf-8"); $mylanguage="php"; $showstr = <<<msg 我最喜愛的網頁程式語言是:$mylanguage <br /> 許多學生都說:"it`s easy,it`s good."msg; echo $showstr; ?> 我照著書上的範例打的理論上應該是會出現我最喜愛的網頁程式語言是:php跟 許多學生都說:it`s easy,it`s good. 可是卻出現Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\learning.php on line 11 我把html的標籤等都砍掉,結果果然是程式把$showstr後面都看成字串了,請問一下 我的heredoc到底那裏出問題? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.143.227.222 ※ 文章網址: http://www.ptt.cc/bbs/PHP/M.1403789755.A.B89.html
LPH66:heredoc 的結束那一行要頂到列首 06/26 21:54
LPH66:你這裡就是 msg; 這行, 左邊不能有空白 06/26 21:54
※ 編輯: joinbee (220.143.227.222), 06/26/2014 21:58:43
joinbee:不好意思我改一下,我的原始程式是這樣 06/26 21:59
※ 編輯: joinbee (220.143.227.222), 06/26/2014 22:02:37
Kenqr:這樣還是有4格空白 06/26 22:03
joinbee:就是都照書上打結果出問題才覺得奇怪 06/26 22:04
※ 編輯: joinbee (220.143.227.222), 06/26/2014 22:06:21
joinbee:是這樣嗎?可是結果一樣耶? 06/26 22:06
joinbee:我懂了謝謝 謝謝 書上的表達方式有問題 06/26 22:11
joinbee:照習慣縮排結果出問題 06/26 22:17
tkdmaf:先不提書上的東西正確與否。這種寫法我個人是不喜歡用。 06/26 23:53
tkdmaf:基本上~~~跟html有關的東西我都不喜歡讓他出現在程式內。 06/26 23:53
thitbbeb:我都習慣這樣寫 http://codepad.org/wZ274BKT 06/27 12:25
thitbbeb:實際寫真的沒看過有用到 <<<msg的..code 06/27 12:25