0

I have a HTML file that contains this code

<head></head>
<body class="page_bg">
Hello, today is <?php echo date('l, F jS, Y'); ?>.
</body>
</html>

and I am wondering why when I run it only says "Hello today i". Without the date. After some research I saw I had to add a .htaccess file with the code AddType application/x-httpd-php .html inside, yet it still only writes "Hello today is ." did I save the .htaccess filethe wrong place or is it something else?

I saved it in in a folder called PHP and HTML test the HTML file and the .htaccess file are both in the same place. I installed PHP with XAMPP.

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Qwertykey
  • 21
  • 5

1 Answers1

0

Make sure your file is saved as .php then run the file through a server. Php cannot run any other way. I use Webstorm which simplifies the process but a quick google search can show you how to setup a localhost server through PHP. Something like php -S localhost:8000 would work, just make sure your PATH (if on windows) has the installation path to PHP.

  • *Technically* `AddType application/x-httpd-php .html` *should* tell the server to treat `.html` files as PHP so you'd not need to rename it to `.php` ... I'd argue that's bad practice mind as it means Apache has to use the PHP interpreter on bog standard HTML pages but that's beside the point. – CD001 May 30 '17 at 13:02