-2

I'm testing the following code. I'm using PHP heredoc but I'm getting an error from dreamweaver. If I write it manually, it works. If I copy paste it doesn't work. Why is that?

<?php

$e=<<<EOP
whoever
EOP;

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

user5402
  • 291
  • 5
  • 16

2 Answers2

4

There is a space after your last closing identifier.

<?php

$e=<<<EOP
whoever
EOP;

$el=<<<EOG
whatever
EOG; 
    ^ right there
?>
  • It needs to be removed.

As per documentation 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.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
1

try to remove a space after "EOG;"

<?php

$el=<<<EOG
whatever
EOG;

?>
  • 3
    Well, this has been clearly pointed out before by others. However if you still post this answer, you should at least remove that space yourself after using copy&paste to copy the code... – arkascha Aug 18 '15 at 17:25