Parse error: syntax error, unexpected $ end in E: \ xampp \ htdocs \ announcements \ announcement.php on line 143

I get this error message

Parse error: syntax error, unexpected $ end in E: \ XAMPP \ HTDOCS \ declarations \ announcement.php on line 143

Line 143 is the last line of the PHP file. When i comment

$htmlcode=<<<eod
<div>$question</div>
<div>$option1  $option2  $option3  $option4</div><br/>
eod;    
echo $htmlcode;

The error has disappeared. What's wrong?

+3
source share
3 answers

What I learned is that after yours eod;, you had some kind of gaps.

Remove the spaces and it will work fine.

Tested:

<?php
$htmlcode=<<<eod
<div>$question</div>
<div>$option1  $option2  $option3  $option4</div><br/>
eod;
echo $htmlcode;
?>
+2
source

You have spaces after eod;

As indicated in manual

, , , (;). , , . , , , . \n UNIX , Mac OS X. (, ) .

+4

heredoc { } :

$htmlcode=<<<eod
<div>{$question}</div>
<div>{$option1}  {$option2}  {$option3}  {$option4}</div><br/>
eod;
echo $htmlcode;

The problem is that PHP is suffocating from the fact that you have no spaces separating the variables $questionand $option4from opening <to your closing tags div.

Also, make sure that eodthere is no space after the semicolon following the separator . The only thing allowed on this line is your separator and semicolon, if necessary.

+1
source

Source: https://habr.com/ru/post/1724071/


All Articles