I am trying to replace HTML code with heredoc statement. However, I get a parsing error on the last line. I am sure that I did not leave a single leading space or indentation on the line of the heredoc closing tag. The following is a piece of code:
$table = <<<ENDHTML
<div style="text-align:center;">
<table border="0.5" cellpadding="1" cellspacing="1" style="width:50%; margin-left:auto; margin-right:auto;">
<tr>
<th>Show I.D</th>
<th>Show Name</th>
</tr>
ENDHTML;
while($row = mysql_fetch_assoc($result)){
extract($row);
$table .= <<<ENDHTML
<tr>
<td>$showid2 </td>
<td>$showname2</td>
</tr>
ENDHTML;
}
$table .= <<<ENDHTML
</table>
<p><$num_shows Shows</p>
</div>
ENDHTML;
echo $table;
?>
Where is the problem? I have a related question in addition to the above. As a coding practice, is it better to use PHP code in everything or is it better to use heredoc syntax. I mean, in PHP mode, the script bounces back and forth between the HTML and the PHP code. So what is the preferred method?
source
share