"heredoc" problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fahim
Forum Commoner
Posts: 36
Joined: Sun Jan 05, 2014 7:06 pm
Location: Dhaka, Bangladesh

"heredoc" problem

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: "heredoc" problem

Post 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;

?>
fahim
Forum Commoner
Posts: 36
Joined: Sun Jan 05, 2014 7:06 pm
Location: Dhaka, Bangladesh

Re: "heredoc" problem

Post by fahim »

WOW!!!! Just exact answer !!!! It's working perfectly now!!! So many thanks for the solution :D .
Post Reply