Execute PHP in HTML


 

Execute PHP in HTML

In this tutorial you will learn about the different ways of executing PHP code into HTML pages.

In this tutorial you will learn about the different ways of executing PHP code into HTML pages.

Execute PHP in HTML

In this tutorial you will learn about the different ways of executing PHP code into HTML pages. In general, we have seen that a page that includes the php code is always named as “. php” because it is the extension of the php file. But in case you do not wanted to change the file name just change the “.htaccess file” and add the following line into it…

1. For HTML
AddType application/x-httpd-php .html

2. For HTM
AddType application/x-httpd-php .htm

There is one more way of doing it… creates a new .php page and add the given lines

<Files my-html-page.html>Add Type application/x-httpd-php.html</Files>

This will make you run your PHP code in .html (my-html-page.html) file.

In the foregoing paragraph we have seen how to execute php in html page. Now lets find out the reason of doing it…

  1. If your page is popular on search engines and giving you lots of traffic, in that situation it’s better to execute php in html page instead of renaming it.
  2. If there is not much programming is required and your page is yet static just execute the php code in HTML.

But I believe that it’s better to change the extension of a page as .php, if we want a dynamic website with lot’s of programming features. This process is know as embedding PHP code in html file, you will learn about it in the next article.

Ads