Page 1 of 1

Embed php tag within .html extension

PostPosted: 05. November 2011 16:09
by chandecweng
Hi all, I can not embed php tag within .html extension.

How can I enable it, will it cause by my editor setting( Aptana Studio ) ?

Thanks a lot for provide me the solution.

Re: Embed php tag within .html extension

PostPosted: 05. November 2011 18:10
by Altrea
Hi chandecweng,

.html files will not be sent through the php parser, that's the reason.

If you want to get php blocks in .html files parsed (which i wouldn't recommend, because there is no good reason for this and the disadvantage will be that even plain html files without php blocks have to go through the php parser unnecessarily), your Apache has to know this.

The setting for this is in your \xampp\apache\conf\extra\httpd-xampp.conf (change lines 20 and 43).

Re: Embed php tag within .html extension

PostPosted: 06. November 2011 06:11
by chandecweng
Altrea wrote:Hi chandecweng,

.html files will not be sent through the php parser, that's the reason.

If you want to get php blocks in .html files parsed (which i wouldn't recommend, because there is no good reason for this and the disadvantage will be that even plain html files without php blocks have to go through the php parser unnecessarily), your Apache has to know this.

The setting for this is in your \xampp\apache\conf\extra\httpd-xampp.conf (change lines 20 and 43).



Hi,Thanks for helping me.

I have change the line 43 like this: AddType text/html .php .phps .html

But I do not know how to change line 20: <FilesMatch "\.php$"> ?

Thanks

Re: Embed php tag within .html extension

PostPosted: 06. November 2011 12:15
by Altrea
How about
Code: Select all
<FilesMatch "\.(php|html)$">

Re: Embed php tag within .html extension

PostPosted: 11. November 2011 20:05
by webdesign.boston
The way to execute PHP on a .html page is to modify your .htaccess file. This file may be hidden, so depending upon your FTP program you may have to modify some settings to see it. Then you just need to add this line for .html:

AddType application/x-httpd-php .html
Or for .htm
AddType application/x-httpd-php .htm
If you only plan on including the PHP on one page, it is better to setup this way:
<Files yourpage.html>
AddType application/x-httpd-php .html
</Files>
This code will only make the PHP executable on the yourpage.html file, and not on all of your html pages.