Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run a PHP script inside a HTML file?

Tags:

How can I run simple PHP code inside a .html file?

like image 768
ABA Avatar asked Apr 04 '14 04:04

ABA


People also ask

Can you run PHP in an HTML file?

You can't, unless you instruct Apache to treat . html files as PHP.

How can I use HTML and PHP together?

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!

How do I start PHP in HTML?

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.


2 Answers

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'

like image 123
Stephane Marchand Avatar answered Sep 19 '22 14:09

Stephane Marchand


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";?> 
like image 39
CMPS Avatar answered Sep 18 '22 14:09

CMPS