Execute PHP scripts into HTML file by Modifying ‘.htaccess’ file

Asreshashank
4 min readJun 9, 2020

PHP and HTML are popular web development technologies, further CSS adds essence to HTML website by making it look decent and user friendly. All 3 components together can help us build the full fledged dynamic website. PHP, short for “Hypertext Preprocessor” supports all the HTML and CSS tags, on top of that, PHP allows us to hard-code Website with PHP scripts. Hence, with basic knowledge in hand, you can start coding and scripting and eventually create your own website.

Now, the Interesting thing is you can use HTML tags in PHP code file, However, you can’t execute PHP script in HTML(.html/.htm) file. In other words, HTML doesn’t understands anything written within<?php …….?>. Even if you wrote php scripts and add it into your HTML file, it simply ignores the script and doesn’t provide any output. Now consider a scenario where, an individual has already built the website using HTML/CSS without realizing that he/she might need a database connection to retrieve data from Database, or lets say the initial requirement changed and now user wants to write some PHP scripts to create features for the website. what can be done in this case?

User might think of shifting an entire website from HTML to PHP and this could be considered as one of the possible solutions, however, it is time consuming at the same time. The another way is to create separate PHP file and call it under <form> tag of HTML as show below.

--

--

No responses yet