PHP not running within HTML Page

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP not running within HTML Page

Postby BarryW » 09. October 2015 04:18

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
BarryW
 
Posts: 2
Joined: 09. October 2015 04:06
Operating System: Win 10

Re: PHP not running within HTML Page

Postby Altrea » 09. October 2015 04:40

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
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11933
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: PHP not running within HTML Page

Postby Nobbie » 09. October 2015 10:31

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.
Nobbie
 
Posts: 13182
Joined: 09. March 2008 13:04

Re: PHP not running within HTML Page

Postby BarryW » 09. October 2015 12:48

Thanks for the replies, now that's out of the way it's on with the learning curve!
BarryW
 
Posts: 2
Joined: 09. October 2015 04:06
Operating System: Win 10


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 148 guests