user2371301
user2371301

Reputation: 3474

PHP INCLUDE function inside an HTML file

I have an HTML file that has a rather long navigation menu inside of it. I want to take that menu out of the HTML and place it into an external PHP page and then call it with

<?php include 'navigation.php'; ?> in the HTML file.

I have tried just adding this into the HTML file but it doesn't display anything as well as no errors on the page.

What do I need to do (if it's even possible) to keep the files HTML and use the php require function?

Upvotes: 0

Views: 89

Answers (2)

Zevi Sternlicht
Zevi Sternlicht

Reputation: 5399

Add this in in your httpd.conf and then you can process PHP code on HTML pages

AddHandler application/x-httpd-php .php .html

Upvotes: 2

paulsm4
paulsm4

Reputation: 121649

Q: Did you give the page a .php suffix? That should be all you need to do.

Remember the way PHP works - you basically "embed" your PHP code in an HTML page, and the server executes the PHP before it serves (the rest of) the HTML.

But in order for PHP to "see" your code, you need to make sure your "HTML page" has a .php suffix.

As a crude workaround, you can add ".html" to the list of file suffixes that PHP will parse.

But this could cause other things to break.

If you want to embed PHP code in your "index.html", the best, cleanest approach is to simply rename it "index.php".

IMHO...

Upvotes: 1

Related Questions