Cannot display php code in test file on WAMP server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bentot
    New Member
    • Mar 2010
    • 5

    Cannot display php code in test file on WAMP server

    For the code below I only see "Hello PhP" and not the Hello World!

    Code:
    <h1>Hello PhP</h1>
    <?php
    echo "Hello World!";
    ?>

    This html file is in the local folder. and the index.php file inside the local folder works because I can see the WampServer Configuration page when I type http://localhost/ on my browser.

    I have Windows Vista

    I don't get it. Please help.
  • Bentot
    New Member
    • Mar 2010
    • 5

    #2
    My file extension is .html so I changed it to .php and it worked. I thought it's possible to include PHP codes in html files?

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hey.

      Technically it is possible, but it is not by default. PHP code needs to be executed by the PHP interpreter. Your HTTP server (Apache, in case of WAMP) is configured to only execute certain types of files as PHP code. These are usually just the .php extensions. Normal .html files are just sent as ordinary, non-php HTML files, but you can tell your server to execute any file as PHP code.

      Everything inside a .php file, except text within <?php ... ?> tags, is considered HTML by the server (by default). So if you rename a .html file to .php you will see no difference at first. - The only difference is that now the file is run through the PHP interpreter, which will look for <?php ... ?> tags and execute them as PHP code. - Everything outside <?php ... ?> tags, and all the output generated by the code inside the tags, is sent to the browser as HTML. - The browser does not see any difference between a normal .html file and a .php file. It's all just HTML from it's perspective.

      Hope that helps :)

      Comment

      Working...