使用php变量的html [关闭]

I have a .html file and another .php file. I want to grab variables from the .php file and use them in my html file. I also have a live.js script that I need to run to update the page when any changes are made.

I can get the php working when I change the file to .php but then my script doesnt work. When I change my file to .html my script works but php doesn't.

Can someone please help me out with getting this fixed. Thank You!

My index.html file right now the php content doesnt show but the script works

<?php include("var.php"); ?>


<html>                                                 
<head>                                                 
<script src="live.js#html"></script>  
<title>MXS</title>                                                            
</head> 
<html>                                         
<body> 
<font color="#FF0000" size="6" face="Comic Sans MS, cursive">MenuXpress</font>


<h1>Cash</h1>
<h1><?php
echo '$' . $tickettotal;
?><h1>

</body>
</body>
</html>

My var.php file with all my variables

<?PHP                                                  


$tickettotal=11.29;                                     
$tendertotal=4.29;                                     
$changetotal=0.00;


?>             

PHP basics: Php is used to generate a html document. Hence in your html the variable should already be avalible. (Through echo).

For php to be able to run the php code. the file always has to have .php extension. (At least as default). so name your file accordingly.

Your code looks fine (except a few html problems, but that shouldn't stop php from working), so i'm thinking that this isn't all the code or maybe the problem derive from elsewere.

I suggest you look up a basic php tutorial.

you need to save index.html file into .php than you access in php file

You can write a lines of htaccess in your .htaccess file in which all html files will be like PHP and your php variables will be parsed automatically.

AddType application/x-httpd-php .html .htm

Change your html file extension to php and it will be fine.

You have to save your index.html file to index.php file because you used PHP code in your file. So server runs the php code and outputs markup, that the browser shows it.

Hope this will help.

Regards