I am trying to replace the HTML code with a heredoc statement. However, I am getting a parse error in the last line.I am sure that I have not left any leading space or indentation on the heredoc closing tag line.Following is a part of the 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 above. As a coding practice, is it better to use PHP code throughout or is it better to use a heredoc syntax. I mean, while in PHP mode, the script bounces back and forth between the HTML and PHP code. So, which is the preferred method?