-3

What is supposed to happen when there is HTML in a here document? Isn't it supposed to just be stored as a string? The HTML in this screen is displayed on screen and so is the delimiter "HTMLBLOCK;" portion of the code. What is going on?

<? php
<<<HTMLBLOCK
<html>
<head><title>Menu</title></head>
<body bgcolor="#fffed9">
<h1>Dinner</h1>
<ul>
<li>Beef Chow-Mun</li>
<li>Sauteed Pea Shoots</li>
<li>Soy Sauce Noodles</li>
</ul>
</body>
</html>
HTMLBLOCK;
?>

OUTPUT

Dinner

Beef Chow-Mun

Sauteed Pea Shoots

Soy Sauce Noodles

HTMLBLOCK; ?>
halfer
  • 19,824
  • 17
  • 99
  • 186
Bendzukic
  • 35
  • 5
  • The space in ` php` is wrong. The rest looks fine. – jh1711 Aug 31 '17 at 22:18
  • A good way to debug these problems is to view the source in your browser. You'll see your PHP in there verbatim, because the web server has not processed it. – halfer Sep 01 '17 at 00:00

1 Answers1

0

Your PHP does have a wrong syntax on the top with: <? php. There should be no space there. Instead of doing that, you could echo the HTML content with PHP; or you can close out of PHP and write out the PHP then open PHP tags again:

echo '<html>
    <head><title>Menu</title></head>
    <body bgcolor="#fffed9">
        <h1>Dinner</h1>
        <ul>
            <li>Beef Chow-Mun</li>
            <li>Sauteed Pea Shoots</li>
            <li>Soy Sauce Noodles</li>
        </ul>
    </body>
</html>';

Or you could do this:

<?php
// .. PHP code here .. 
?>
<html>
    <head><title>Menu</title></head>
    <body bgcolor="#fffed9">
        <h1>Dinner</h1>
        <ul>
            <li>Beef Chow-Mun</li>
            <li>Sauteed Pea Shoots</li>
            <li>Soy Sauce Noodles</li>
        </ul>
    </body>
</html>
<?php
// ..code continues..
?>

You could also store the HTML in a variable and `echo the variable.

Sam
  • 2,856
  • 3
  • 18
  • 29