作者joinbee (二老林)
看板PHP
標題[請益] heredoc?
時間Thu Jun 26 21:35:52 2014
<?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://webptt.com/m.aspx?n=bbs/PHP/M.1403789755.A.B89.html
1F:→ LPH66:heredoc 的結束那一行要頂到列首 06/26 21:54
2F:→ LPH66:你這裡就是 msg; 這行, 左邊不能有空白 06/26 21:54
※ 編輯: joinbee (220.143.227.222), 06/26/2014 21:58:43
3F:→ joinbee:不好意思我改一下,我的原始程式是這樣 06/26 21:59
※ 編輯: joinbee (220.143.227.222), 06/26/2014 22:02:37
4F:→ Kenqr:這樣還是有4格空白 06/26 22:03
5F:→ joinbee:就是都照書上打結果出問題才覺得奇怪 06/26 22:04
※ 編輯: joinbee (220.143.227.222), 06/26/2014 22:06:21
6F:→ joinbee:是這樣嗎?可是結果一樣耶? 06/26 22:06
7F:→ joinbee:我懂了謝謝 謝謝 書上的表達方式有問題 06/26 22:11
8F:→ joinbee:照習慣縮排結果出問題 06/26 22:17
9F:→ tkdmaf:先不提書上的東西正確與否。這種寫法我個人是不喜歡用。 06/26 23:53
10F:→ tkdmaf:基本上~~~跟html有關的東西我都不喜歡讓他出現在程式內。 06/26 23:53
12F:→ thitbbeb:實際寫真的沒看過有用到 <<<msg的..code 06/27 12:25