lesterpierson123
lesterpierson123

Reputation: 165

Separating an HTML header into a different PHP document

This sounds incredibly simple but has boggled my website for the past day. I'm really just trying to move my HTML header into a separate php file.

This is how the HTML header looks before change (works fine):

<div class = "header">
<h1>The Trade Shack<em id="demo"></em></h1>
</div>

And now I'm trying to set it in a separate php file:

<div class = "header">
<?php include "header.php"; ?>
</div>

And the header.php file:

    <?php
echo ("<h1>The Trade Shack<em id=""demo""></em></h1>");
?>

On paper, this should work absolutely fine since my header.php file is just echoing what was written in the HTML file before. Why doesn't this work them? I don't have anything in my div header when I load the page.

Upvotes: 0

Views: 44

Answers (2)

prasanth
prasanth

Reputation: 22510

Its a syntax error

Try like this : change the quotes like this below start and end ' is single quotes

<?php
echo '<h1>The Trade Shack<em id="demo"></em></h1>';
?>

Upvotes: 0

WEBjuju
WEBjuju

Reputation: 6591

Because of this:

Parse error: syntax error, unexpected '"demo"' (T_CONSTANT_ENCAPSED_STRING) in (your file) on line 2

Your header.php is not printing anything. If you don't have any php to process...just change the header.php to have this in it:

<h1>The Trade Shack<em id="demo"></em></h1>

If you need php, just note that you need to "escape" your double quotes embedded within double quotes like this:

echo "<h1>The Trade Shack<em id=\"demo\"></em></h1>";

But that is even more easily handled by using single quotes:

echo '<h1>The Trade Shack<em id="demo"></em></h1>';

Upvotes: 1

Related Questions