How can I run simple PHP code inside a .html file?
You can't, unless you instruct Apache to treat . html files as PHP.
1- You can combine them with PHP echo statement like this: <? php echo "<html>"; echo "<title>HTML with PHP</title>"; echo "<b>My Example</b>"; //your php code here // Or you can use the print command print "<i>Print works too!
Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to use the PHP. Step 2: Now, we have to place the cursor in any tag of the <body> tag where we want to add the code of PHP. And, then we have to type the start and end tag of PHP.
To execute 'php' code inside 'html' or 'htm', for 'apache version 2.4.23'
Go to '/etc/apache2/mods-enabled' edit '@mime.conf'
Go to end of file and add the following line:
"AddType application/x-httpd-php .html .htm"
BEFORE tag '< /ifModules >' verified and tested with 'apache 2.4.23' and 'php 5.6.17-1' under 'debian'
You can't run PHP
in an html page ending with .html
. Unless the page is actually PHP and the extension was changed with .htaccess
from .php
to .html
What you mean is:
index.html <html> ... <?php echo "Hello world";?> //This is impossible index.php //The file extension can be changed using htaccess, ex: its type stays php but will be visible to visitors as index.html <?php echo "Hello world";?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With