PHP code in HTML file

Discussion in 'PHP' started by annvijay, Jul 25, 2008.

  1. #1
    Hi,
    I am new to php and html. Here my question Is there possible to have PHP code in .html file like these

    I created a test file and filename it test.html


    <html>
    <head></head>
    <body>
    <h1>
    <?php echo "I LOVE PHP!"; ?>
    </h1>
    </body>
    </html>

    When I execute this test.html file its not working means not executing the php code.Is it possible to execute these file.
    If it is not possible Why? Waiting for quick reply.

    thanks
     
    annvijay, Jul 25, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    It doesn't work because the server doesn't parse HTML files by default. You can enable it with .htaccess, though.
    
    AddType x-httpd-php .php .htm .html
    
    Code (markup):
     
    nico_swd, Jul 25, 2008 IP
  3. lamborevijay

    lamborevijay Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Chk. if u have the file test.html in the document root of PHP thts "htdocs" folder.
     
    lamborevijay, Jul 25, 2008 IP
  4. annvijay

    annvijay Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi guys
    Thanks for your quick reply. i just tried AddType x-httpd-php .php .htm .html this code in .htaccess file but still i am
    not getting i dont know why? Anybody tell where to put this .htaccess file. it will helpfull for me.

    thanks
     
    annvijay, Jul 25, 2008 IP
  5. pwaring

    pwaring Well-Known Member

    Messages:
    846
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    135
    #5
    You might not be able to use Add-Type in your .htaccess file - what you can and can't include in those files (and indeed whether you can even use them at all) is controlled by how your server admin has set up the Apache configuration (assuming you're running Apache - you could be on a IIS host).

    If you have a PHP-enabled host, give your files a .php extension, that way they will definitely be parsed as PHP. Any other solution, such as messing around with Add-Type, is far more reliant on your individual setup and therefore less likely to work.
     
    pwaring, Jul 25, 2008 IP