2011-06-14 36 views
1

可能重複:
HEREDOC interfering with code indentation我用heredoc語法來覆蓋我的字符串。但它顯示錯誤。下面是我的代碼:

<?php 
     $my_string = <<<TO 
     Everything in this rather unnecessarily wordy 
     ramble of prose will be incorporated into the 
     string that we are building up inevitably, 
     inexorably, character by character, line by line, 
     until we reach that blessed //final line which is this one. 
     TO; 
     echo $my_string; 
    ?> 

它的錯誤是:

Parse error: syntax error, unexpected $end in C:\wamp\www\ITP - Teaching\PHP\Chapter VIII - String\Heredoc Syntax\index.php on line 19 

回答

6

收盤TO不能縮進。

+0

感謝傢伙。有用 – 2011-06-14 11:02:04

2

定界符結束必須在行的開始,試試這個:

<?php 
     $my_string = <<<TO 
     Everything in this rather unnecessarily wordy 
     ramble of prose will be incorporated into the 
     string that we are building up inevitably, 
     inexorably, character by character, line by line, 
     until we reach that blessed //final line which is this one. 
TO; 
     echo $my_string; 
    ?> 
相關問題