Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
75
rated 0 times [  81] [ 6]  / answers: 1 / hits: 16938  / 12 Years ago, mon, may 14, 2012, 12:00:00

I know that there are many questions about this but I cannot make it work.



My HTML (test.htm) has only this code



<?php
$var = 'foo';
?>
<script type=text/javascript language=javascript>
var val = <?=$var?>;
alert(val);
</script>


But when I open the file with the browser the value of val is <?=$var?> and not 'foo'



How can I make it work?


More From » php

 Answers
9

Unless you have some configuration to allow it, .htm files won't execute PHP code, you'll have to use a .php file.



If you look at your HTML page source in the browser, you'll probably see all the PHP code.



The only other explanation is that short tags <? ?> aren't enabled, you'll have to use
<?php echo $var; ?>


[#85599] Saturday, May 12, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eanskylerg

Total Points: 524
Total Questions: 107
Total Answers: 100

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
;