But when I open the file with the browser the value of val is "" and not 'foo'
Sounds like you have shorttags disabled shorttags disabled (and are using PHP < 5.4.0). Try
var val = "<?php echo $var ?>";
Edit: And note CM Kanode's comment on the question: If it's a .htm file, odds are that your server isn't running it through PHP at all (that would take special configuration and probably not be a good idea). (You are opening this via an http:// URL, right? Not opening the file locally? Because unless the PHP server gets involved, the PHP tags can't be processed.)
And better yet, let json_encode make sure the value is property quoted and such for you:
var val = <?php echo json_encode($var) ?>;
But when I open the file with the browser the value of val is "" and not 'foo'
Sounds like you have shorttags disabled (and are using PHP < 5.4.0). Try
var val = "<?php echo $var ?>";
Edit: And note CM Kanode's comment on the question: If it's a .htm file, odds are that your server isn't running it through PHP at all (that would take special configuration and probably not be a good idea). (You are opening this via an http:// URL, right? Not opening the file locally? Because unless the PHP server gets involved, the PHP tags can't be processed.)
And better yet, let json_encode make sure the value is property quoted and such for you:
var val = <?php echo json_encode($var) ?>;
But when I open the file with the browser the value of val is "" and not 'foo'
Sounds like you have shorttags disabled (and are using PHP < 5.4.0). Try
var val = "<?php echo $var ?>";
Edit: And note CM Kanode's comment on the question: If it's a .htm file, odds are that your server isn't running it through PHP at all (that would take special configuration and probably not be a good idea). (You are opening this via an http:// URL, right? Not opening the file locally? Because unless the PHP server gets involved, the PHP tags can't be processed.)
And better yet, let json_encode make sure the value is property quoted and such for you:
var val = <?php echo json_encode($var) ?>;
But when I open the file with the browser the value of val is "" and not 'foo'
Sounds like you have shorttags disabled (and are using PHP < 5.4.0). Try
var val = "<?php echo $var ?>";
Edit: And note CM Kanode's comment on the question: If it's a .htm file, odds are that your server isn't running it through PHP at all (that would take special configuration and probably not be a good idea). (You are opening this via an http:// URL, right? Not opening the file locally? Because unless the PHP server gets involved, the PHP tags can't be processed.)
And better yet, let json_encode make sure the value is property quoted and such for you:
var val = <?php echo json_encode($var) ?>;
But when I open the file with the browser the value of val is "" and not 'foo'
Sounds like you have shorttags disabled (and are using PHP < 5.4.0). Try
var val = "<?php echo $var ?>";
And better yet, let json_encode make sure the value is property quoted and such for you:
var val = <?php echo json_encode($var) ?>;
But when I open the file with the browser the value of val is "" and not 'foo'
Sounds like you have shorttags disabled (and are using PHP < 5.4.0). Try
var val = "<?php echo $var ?>";
Edit: And note CM Kanode's comment on the question: If it's a .htm file, odds are that your server isn't running it through PHP at all (that would take special configuration and probably not be a good idea). (You are opening this via an http:// URL, right? Not opening the file locally? Because unless the PHP server gets involved, the PHP tags can't be processed.)
And better yet, let json_encode make sure the value is property quoted and such for you:
var val = <?php echo json_encode($var) ?>;
But when I open the file with the browser the value of val is "" and not 'foo'
Sounds like you have shorttags disabled (and are using PHP < 5.4.0). Try
var val = "<?php echo $var ?>";
And better yet, let json_encode make sure the value is property quoted and such for you:
var val = <?php echo json_encode($var) ?>;