1

I am trying to run PHP in HTML page.

I saved this file in WAMP as a .html

<html>
  <body>
    <?php echo "My first PHP script!";?>
  </body>
</html>

But when I open it with the browser and I do inspect element the result is this:

<html>
    <head></head>
    <body>
        <!--?php
            echo "My first PHP script!";
        ?--> 
    </body>
</html>
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Milton90
  • 547
  • 2
  • 7
  • 15

6 Answers6

4

If Apache is not running .html pages as php scripts then running a .html page won't run as .php

Ron
  • 514
  • 2
  • 13
Naftali
  • 144,921
  • 39
  • 244
  • 303
2

Solution: Rename your filename from something.html to something.php

or alternatively something.phtml although this is uncommon

Ron
  • 514
  • 2
  • 13
1

You can also save the page as .phtml. This format is possible of displaying .php & .html.

Take a look here for more information: What is phtml, and when should I use a .phtml extension rather than .php?

Community
  • 1
  • 1
Benz
  • 2,317
  • 12
  • 19
0

You should save it as .php instead of .html

Ollie
  • 196
  • 16
0

You need to put it into a .php file, the webserver (if not configured so) won't interpret .html files as PHP.

bwoebi
  • 23,637
  • 5
  • 58
  • 79
0

Like others said, by changing file extension from .html to .php would work. However, if you don't want to do that, you may want to check this out. It allows you to execute php file without change file extension.

user1139921
  • 143
  • 3
  • 13