How to assign Php variable value to Javascript variable? [duplicate]

Essentially:

<?php
//somewhere set a value
$var = "a value";
?>

<script>
// then echo it into the js/html stream
// and assign to a js variable
spge="<?php echo $var ;?>";

// then
alert(spge);

</script>

Leave a Comment