将php变量分配给javascript警告PHP源代码

I want to assign the php variable $stop to the javascript variable stopped

<?php
    $stop = $_POST['stop'];
?>
<script>
    var stopped = "<?php echo($stop) ?>";
    alert(stopped); //Output: alertbox with the text: <?php echo($stop) ?>
</script>

How can I solve this?

Since the PHP source code is being alerted, the document is not being run through the PHP preprocessor before being delivered to the browser.

Make sure that:

  • You're using a web server and not loading from a local file
  • The webserver supports PHP
  • The file the PHP code is in is one the server expects to find PHP in (typically this will be a file with a .php extension, but it is configurable).