Page 1 of 1

PHP not running within HTML Page

PostPosted: 09. October 2015 04:18
by BarryW
Hi, a total noobie with all this so please bear with me.

I have created a small HTML file

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


When I open up the page in my browser at 127.0.0.1/test1.html I get the following:

Hello, today is .

The HTML code is displayed, but no PHP code.

If I rename the same file test1.php and open it in the browser I get the correct display of

Hello, today is Friday, October 9th, 2015.

Should the html file work with embedded php?

Thanks

Re: PHP not running within HTML Page

PostPosted: 09. October 2015 04:40
by Altrea
Hi,

Short answer: no.
The PHP interpreter don't expect any PHP inside of .html files.

At the end it is configurable which file extensions are send through the php Interpreter, but it is highly recommend to get comfortable with this setting as it is now.

Best wishes,
Altrea

Re: PHP not running within HTML Page

PostPosted: 09. October 2015 10:31
by Nobbie
BarryW wrote:If I rename the same file test1.php and open it in the browser I get the correct display of


Thats exactly how it is supposed to work. PHP Scripts should have extension *.php. There is actually no difference between "Embedded PHP in HTML" and plain PHP, its quite the same.

Re: PHP not running within HTML Page

PostPosted: 09. October 2015 12:48
by BarryW
Thanks for the replies, now that's out of the way it's on with the learning curve!