Skip to main content
A_Liebscher
Inspiring
May 30, 2012
Answered

echo <<<END / heredocs

  • May 30, 2012
  • 2 replies
  • 2504 views

I have seen "heredocs" used, but for some reason I can't duplicate it! I want to echo a string, obviously, and this string will contain html text. When I run this code, it comes back with:

Parse error: syntax error, unexpected $end in /home/public_html/xxxx.php on line 97

So I'm going to post some code here, and if you have some sort of advice, that'd be great, if not, maybe you could learn what not to do.

function display()

{

     echo <<<END

     <div>

     <p>Here is some example code in an example that is not working.</p>

     </div>

     END;

}

Thanks, Alex Liebscher

This topic has been closed for replies.
Correct answer A_Liebscher

Nevermind! I concluded that in order for the heredoc to work, the start and end (echo <<<END , END;) need to be left justified.

So things would look like this:

function display()

{

echo <<<END   

     <div>

     Here is some example code in an example that is not working.

     </div>

END;

}

Thanks though, Alex Liebscher

2 replies

zagarskas
Known Participant
September 16, 2016

Check out this idea for a patch I use, and to vote on an idea!

A_Liebscher
A_LiebscherAuthorCorrect answer
Inspiring
May 30, 2012

Nevermind! I concluded that in order for the heredoc to work, the start and end (echo <<<END , END;) need to be left justified.

So things would look like this:

function display()

{

echo <<<END   

     <div>

     Here is some example code in an example that is not working.

     </div>

END;

}

Thanks though, Alex Liebscher