php in html file

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

php in html file

Postby jwzumwalt03 » 14. June 2022 03:34

I just installed XAMP in Ubuntu 22.04 and it runs standalone php files
fine but I cant get php embedded in html to work. I have never used
XAMP with linux before... what am I doing wrong?

file name = test.html (this file does NOT run, it just shows the JS)
Code: Select all
<html>
<body>
<h1>JS - Hello World</h1>
<h1><?php echo "PHP - Hello World" ?></h1>  <!-- does not work -->
</body>
</html>


file name = test.php (this file runs great)
Code: Select all
<?php
echo "hello world!";
?>


Thanks for the help :)
jwzumwalt03
 
Posts: 2
Joined: 14. June 2022 03:23
XAMPP version: 8.1.6.0
Operating System: Ubuntu 22.04

Re: php in html file

Postby Altrea » 14. June 2022 07:04

file extension .html will not get sent through the php interpreter.
If you want to mix and match php and html code in the same file, simply use the .php file extension.
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: 11583
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: php in html file

Postby jwzumwalt03 » 14. June 2022 07:33

Thanks, it did work (as you suggested) when I changed the extension.

I have not worked with PHP for 5 years but it seems
to me I was able to do that 5 yrs ago on win machines?

I was working on remote servers a lot then, maybe it was
a remote server? Or is it a config setting?
jwzumwalt03
 
Posts: 2
Joined: 14. June 2022 03:23
XAMPP version: 8.1.6.0
Operating System: Ubuntu 22.04

Re: php in html file

Postby Altrea » 14. June 2022 08:20

it is a config which files are handled in which way.
But it is bad practice to send html files through the php interpreter.
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: 11583
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: php in html file

Postby Nobbie » 14. June 2022 19:13

jwzumwalt03 wrote:file name = test.php (this file runs great)


Exactly, thats how it works. Do NOT put PHP Code into .html files, instead put HTML into .php files.
Nobbie
 
Posts: 12460
Joined: 09. March 2008 13:04


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 9 guests