I am having a problem with a simple php file in which I am trying to pass a variable from php to javascript. I have used the exact same code successfully in a more complex program, but cannot get it to work in the most trivial context here. Below is the entire code. When I run it, it complains that xxx is an unidentified variable:
<?php
echo "<h2 style='text-align: center'>Welcome</h2><br>";
echo '<script>var xxx = "Hello";</script>'
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
echo xxx;
</script>
</body>
</html>
I know there are other ways to pass data from php to js, but this one is simplest and I have used it before. Why is it failing here?