Reputation: 25304
I get this error message
Parse error: syntax error, unexpected $end in E:\xampp\htdocs\announcements\announcement.php on line 143
Line 143 is the last line of the PHP file. When I comment out
$htmlcode=<<<eod
<div>$question</div>
<div>$option1 $option2 $option3 $option4</div><br/>
eod;
echo $htmlcode;
The error is gone. What's wrong?
Upvotes: 3
Views: 1492
Reputation: 43619
What I found out what after your eod;
, you had some whitespaces there.
Remove the whitespaces and it will work fine.
Tested:
<?php
$htmlcode=<<<eod
<div>$question</div>
<div>$option1 $option2 $option3 $option4</div><br/>
eod;
echo $htmlcode;
?>
Upvotes: 2
Reputation: 26863
Enclose the variable names inside your heredoc
block with {
and }
like so:
$htmlcode=<<<eod
<div>{$question}</div>
<div>{$option1} {$option2} {$option3} {$option4}</div><br/>
eod;
echo $htmlcode;
The problem is that PHP chokes on the fact that you have no whitespace separating your $question
and $option4
variables from the opening <
for your closing div
tags.
Also, ensure that there's no whitespace after the semicolon following your eod
delimiter. The only thing allowed on that line is your delimiter and a semicolon if necessary.
Upvotes: 1
Reputation: 10210
You have spaces after eod;
As stated in the manual
It is very important to note that the line with the closing identifier must contain no other characters, except possibly 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 (possibly followed by a semicolon) must also be followed by a newline.
Upvotes: 4