0

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.

1
  • Why did you omit <em>? Commented Dec 6, 2016 at 5:21

2 Answers 2

1

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>';
Sign up to request clarification or add additional context in comments.

5 Comments

Now see, even when I try to run my website after that, the header doesn't appear. I've deleted everything in my header.php and only did echo '<h1>The Trade Shack<em id="demo"></em></h1>';
@lesterpierson123 update the question to show your updated code. Enable error reporting and check your error logs.
is header.php in the same folder as the calling file? have you tried it with only html in it and no php at all? @chris85 is right, though, you need to find your php error log.
@WEBjuju I have tried it without php and only html, it works fine. I have no idea how to check error logs as this is a simple website assignment :/
you must still have a syntax error. you should find your php error log, and the assignment would feel much more simple to you. it takes much less time to see in the error log that header.php has a syntax error than it does to post on this website and wait to be informed of it.
0

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>';
?>

1 Comment

Your comment, () remove the brackets, has no relevance to the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.