Page 1 of 1

php in html file

PostPosted: 14. June 2022 03:34
by jwzumwalt03
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 :)

Re: php in html file

PostPosted: 14. June 2022 07:04
by Altrea
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.

Re: php in html file

PostPosted: 14. June 2022 07:33
by jwzumwalt03
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?

Re: php in html file

PostPosted: 14. June 2022 08:20
by Altrea
it is a config which files are handled in which way.
But it is bad practice to send html files through the php interpreter.

Re: php in html file

PostPosted: 14. June 2022 19:13
by Nobbie
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.