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
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):
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
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.