Enemy of the State Enemy of the State - 1 month ago 17
PHP Question

Heredoc not working

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

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;