Reputation: 574
I'm pretty new to web development and I am trying to learn by trying to develop a website of course. However, I am hitting an issue, I don't get why my include function in PHP is not working.
My 'menu.php' file contains:
<?php
echo '
<li><a href="#" class="current">Home</a></li>
<li><a href="#">button1</a></li>
<li><a href="#">button2</a></li>
<li><a href="#">button3</a></li>
<li><a href="#">button4</a></li>
<li><a href="#">button5</a></li> ';
?>
My html file contains the following:
...
<nav>
<ul>
<?php include 'menu.php'; ?>
</ul>
</nav>
...
What am I missing? If I copy the list items from my .php to my .html, it works properly. It works:
...
<nav>
<ul>
<li><a href="#" class="current">Home</a></li>
<li><a href="#">button1</a></li>
<li><a href="#">button2</a></li>
<li><a href="#">button3</a></li>
<li><a href="#">button4</a></li>
<li><a href="#">button5</a></li>
</ul>
</nav>
...
Thank you in advance.
Upvotes: 1
Views: 489
Reputation: 519
You cannot put PHP content in an HTML file, it won't be processed as such. You should rename your .html page to .php.
Upvotes: 1
Reputation: 324800
When you say:
My html file contains the following:
Do you mean that you have a file like index.html
? Because that means that PHP is not being parsed. All that's happening is that you have a weird <?php>
element that gets silently ignored as invalid HTML.
Try renaming your file to index.php
instead.
As an aside, you should always use the browser's View Source option before saying it doesn't do anything ;)
Upvotes: 3