以下 PHP 代码中的错误是什么?

What's the error in the following PHP code?

我正在测试以下代码。我正在使用 PHP heredoc,但我从 Dreamweaver 收到错误消息。如果我手动编写它,它就可以工作。如果我复制粘贴它不起作用。这是为什么?

<?php

$e=<<<EOP
whoever
EOP;

$el=<<<EOG
whatever
EOG; 
?>

最后一个结束标识符后有一个 space。

<?php

$e=<<<EOP
whoever
EOP;

$el=<<<EOG
whatever
EOG; 
    ^ right there
?>
  • 需要删除。

根据文档http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

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.

尝试删除 "EOG;"

之后的 space
<?php

$el=<<<EOG
whatever
EOG;

?>