<?php $myvar = '1234'; echo '<script>var myvar = "'+$myvar+'"</script>'; ?> <html> <body> <script> alert(myvar); </script> </body> </html>