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>
6
  • 2
    delete your file, and won't show it :)) or just rename to .php :)) Commented Jul 3, 2013 at 14:31
  • Hahaha, it works ok. Thank you. It's my first php, I wanted to test... Commented Jul 3, 2013 at 14:34
  • 6
    @Downvoters - Why down vote this question? Sure, it's simple but it's well structured and on topic. Commented Jul 3, 2013 at 14:34
  • 4
    Only Chuck Norris can run php in html file. Commented Jul 3, 2013 at 14:38
  • 2
    @slavoo - Him and John Skeet! ;) Commented Jul 3, 2013 at 14:38

6 Answers 6

4

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

or alternatively something.phtml although this is uncommon

Comments

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?

3 Comments

Take a look here for more information: stackoverflow.com/questions/11859015/…
Best to add that information against your answer for clarity :)
I will do that the next time, thq you @webnoob
0

You should save it as .php instead of .html

Comments

0

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

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.