Page 1 of 1

"heredoc" problem

Posted: Wed Apr 09, 2014 10:06 am
by fahim
As a new learner of PHP, I'm trying to test heredoc with the following code :

Code: Select all

<?php
$movie=<<<EOD
	<h2><center>Movie Review Database</center></h2>
	<table width="70%" border="1" cellpadding="2" cellspacing="2" align="center">
		<tr>
			<th>Movie Title</th>
			<th>Year of Release</th>
			<th>Movie Director</th>
			<th>Movie Lead Actor</th>
			<th>Movie Type</th>
		</tr>
	</table>
	EOD;
	
	echo $movie;
	
?>
Unfortunately, I'm getting the following error : [text]
Parse error: syntax error, unexpected end of file in /opt/lampp/htdocs/chapter4/table1.php on line 18[/text]

After some searching I found that, this error message could show if there is any space between the tags. I've checked several times but no luck. same error again & again!!!

Experts please help me overcome this message. Thanks in advance.

Re: "heredoc" problem

Posted: Wed Apr 09, 2014 10:15 am
by Celauran
Remove the spaces before EOD.

Code: Select all

<?php
$movie=<<<EOD
        <h2><center>Movie Review Database</center></h2>
        <table width="70%" border="1" cellpadding="2" cellspacing="2" align="center">
                <tr>
                        <th>Movie Title</th>
                        <th>Year of Release</th>
                        <th>Movie Director</th>
                        <th>Movie Lead Actor</th>
                        <th>Movie Type</th>
                </tr>
        </table>
EOD;

        echo $movie;

?>

Re: "heredoc" problem

Posted: Wed Apr 09, 2014 1:15 pm
by fahim
WOW!!!! Just exact answer !!!! It's working perfectly now!!! So many thanks for the solution :D .