2014-09-04 26 views
3

下面的代碼是顯示一個解析錯誤:定界符錯誤,顯示解析錯誤

Parse error: syntax error, unexpected $end, expecting T_VARIABLE 
or T_END_HEREDOC 
or T_DOLLAR_OPEN_CURLY_BRACES 
or T_CURLY_OPEN in D:\xampp\htdocs\project1\conf.php 
on line 10 

這是我在conf.php文件

$chat_code = 
<<<EOD 

<script>alert('Hi')</script> 

EOD; 
+2

您提供的代碼不顯示任何錯誤。檢查'EOD;'沒有前導符號。 – BlitZ 2014-09-04 08:33:39

+2

'EOD;'後面需要換行符。 – 2014-09-04 08:34:49

+0

@NisseEngström謝謝,我添加了新的行,現在工作 – 2014-09-04 08:36:15

回答

3

代碼從manual

Warning: It is very important to note that the line with the closing identifier must contain no other characters, except a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter must also be followed by a newline. If this rule is broken and the closing identifier is not "clean", it will not be considered a closing identifier, and PHP will continue looking for one. If a proper closing identifier is not found before the end of the current file, a parse error will result at the last line. Heredocs can not be used for initializing class properties. Since PHP 5.3, this limitation is valid only for heredocs containing variables.

因此,您的heredoc字符串關閉分隔符應該沒有前導符號,也沒有後續符號,除了新行符號。