我使用heredoc语法来覆盖我的字符串。但它显示错误。以下是我的代码:

时间:2011-06-14 10:54:00

标签: php

  

可能重复:
  HEREDOC interfering with code indentation

<?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

2 个答案:

答案 0 :(得分:6)

结尾TO不得缩进。

答案 1 :(得分:2)

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;
    ?>