pass php variable to javascript
snippet in javascript

php pass a variabele to js

user3915

<script>
'var name = <?php echo json_encode($name); ?>;
</script>'

pass php variable to javascript

user8422

//passing PHP variable to JavaScript
var myJSVar = <?php echo json_encode($myPHPVar); ?>;

how to use php echo data in javascript

user9921

<?php
$php_variable = 'string'; //Define our PHP variable. You can of course get the value of this variable however you need.
?>			
        <script> js_variable_name = "<?php echo $php_variable; ?>";</script>

send php variable to javascript

user5593

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        How to pass variables and data 
        from PHP to JavaScript? 
    </title> 
</head> 
  
<body style="text-align:center;"> 
      
    <h1 style="color:green;">GeeksforGeeks</h1> 
      
    <h4> 
        How to pass variables and data 
        from PHP to JavaScript? 
    </h4> 
      
    <?php 
        $name = "Hello World"; 
    ?> 
  
    <script type="text/javascript"> 
        var x = "<?php echo"$name"?>"; 
        document.write(x); 
    </script> 
</body> 
  
<html>