PHP is a server-side scripting language. That means a PHP script is executed on the server, the output is built on the server, and the result is sent as HTML to the client browser for rendering. It is quite common to code PHP within HTML in a script.
Many complex scripts may require you to combine the features of HTML and PHP to achieve the required results. Even though they are different languages, with their own respective functions, it doesn’t change the fact that PHP is designed to interact with HTML scripts.
A PHP script can easily be integrated within an HTML script and treated as HTML. On any HTML page, the PHP code is enclosed within PHP tags, <?php
and ?>
. When the visitor opens the page in a browser, the PHP compiler and the server processes the PHP code enclosed within PHP tags. Everything within the PHP tags is processed by the PHP compiler. The server then sends the output from the PHP code to the user’s browser, where it is displayed.
.html
to create an HTML file.<h1> This is html script </h1>
<?php
echo "hello world in php";
?>
.html
file so that it runs on the browser.When we run the file, the output does not print the code in the PHP column because the .html
file does not recognize the PHP notation. This is where we use an
In the same folder where you have saved the .html
file, open a new notepad text document and save it with the extension of htaccess
.
Edit the .htaccess
file and add the following command. This makes sure the browser recognizes the PHP script within the HMTL script file.
AddType application/x-httpd-php .htm .html
.html
file in the browser to view the expected output.Free Resources