tags:

views:

35

answers:

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

A: 

Try the following:

<?php
$information = <<<EOS
Hello world!
EOS;
echo $information;
?>
Richard Cook
Why the down-vote? The answer seems to be correct, albeit with no *explanation* of what the error *was*, or might've been. Incidentally, @Richard Cook, here's a pretty awesome guide (from @Jon Skeet) to answering questions. :)
David Thomas
I did wonder about that myself. I will beef up my answers a little more in the future!
Richard Cook
It's confusing. It might suggest that somehow `INFO` cannot be used as heredoc delimiter or something like that...
Crozin
I hadn't thought of that. Thanks for comment.
Richard Cook
Not my DV, but your answer doesn't show whitespace, and the problem with the code was bad placement of whitespace.
Peter Ajtai
+2  A: 

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;
Robert Elwell
That was it thank you
Enemy of the State
A: 

I've just edited your question and fixed invalid formatting (SO is using Markdown). I found out that there is a space character after <<<INFO - that causes the error.

Delete that space and everything should work fine... well - it has to works fine.

Crozin