Heredoc not working

Enemy of the State picture Enemy of the State · Sep 18, 2010 · Viewed 13.7k times · Source
<?php

$information = <<<INFO 
Name: John Smith
Address: 123 Main St
City: Springville, CA
INFO;

echo $information;

?>

Result:

Parse error: syntax error, unexpected T_SL on line 3

Answer

Robert Elwell picture Robert Elwell · Sep 18, 2010

The parser is complaining because you have whitespace after the angled brackets declaring a heredoc. You need to make sure you're actually following the heredoc syntax, which you can find on the PHP Manual site (specifically: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc).

<?php
$information = <<<ENDHEREDOC
this is my text
ENDHEREDOC;
echo $information;