PHP include statement in an HTML document

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpvirgin
Forum Newbie
Posts: 2
Joined: Thu Apr 19, 2007 11:37 am

PHP include statement in an HTML document

Post by phpvirgin »

Hey everyone,

I'm a PHP newbie and have what probably is going to be a stupid question but I can't find examples or info on it. I have an HTML document and in that document I have an include statement <?php include("showme.php")?>. When I load the HTML document, the contents of the PHP file isn't displayed. If I put the appropriate include statement in another php file to load showme.php, it works. So is it possible to have an include statement that loads a PHP file embedded in an HTML document?

Thx
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

Is the file that doesn't work with the include have a .html or .php extension?

If I remember right, it needs to have a .php extension. Either that, or the path for the included file isn't right on the html document.
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

As far as i know php will not parse html files. You could do something like this but like the commenter said, that forces your server to parse every html file for php which increases the load on your server. If you change the extension of that html file to php it should work (with the adition of a semicolon (';') at the end of your echo statement).

Wayne
User avatar
bert4
Forum Newbie
Posts: 18
Joined: Wed Apr 18, 2007 9:44 am
Location: Bali, Indonesia

Post by bert4 »

Add this line to your .htaccess file:

Code: Select all

AddType application/x-httpd-php .htm .html
But beware, your htm(l) documents will be treated as php !!!
phpvirgin
Forum Newbie
Posts: 2
Joined: Thu Apr 19, 2007 11:37 am

Post by phpvirgin »

Thx folks.

I'll rethink my structure because I definitely want to avoid having all the HTML parsed 8O

Cheers
Post Reply