Page 1 of 1

PHP include statement in an HTML document

Posted: Thu Apr 19, 2007 12:02 pm
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

Posted: Thu Apr 19, 2007 12:29 pm
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.

Posted: Thu Apr 19, 2007 12:44 pm
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

Posted: Thu Apr 19, 2007 12:45 pm
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 !!!

Posted: Thu Apr 19, 2007 12:50 pm
by phpvirgin
Thx folks.

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

Cheers