Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

replaced http://uk3.php.net with https://www.php.net
Source Link

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) ?>;
added 377 characters in body
Source Link
T.J. Crowder
  • 1.1m
  • 201
  • 2k
  • 2k

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) ?>;
Source Link
T.J. Crowder
  • 1.1m
  • 201
  • 2k
  • 2k

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) ?>;
default

AltStyle によって変換されたページ (->オリジナル) /