How to add php content or variable inside javascript alert box?! javascript, php, alertbox

前端 未结 5 1939
失恋的感觉
失恋的感觉 2020-12-18 17:09

How can i add php content or php variable inside Java-script alert box?! I tried to make it work few ways but it is only popping up a blank box rather than the contents of p

相关标签:
5条回答
  • 2020-12-18 17:24

    Change this

    alert (<?php $b ?>);
    

    to this

    alert ('<?php echo $b; ?>');
    

    You need to output the value of $b and add quotes inside the alert.

    About PHP - echo

    0 讨论(0)
  • 2020-12-18 17:34

    1.

    <script>
      alert("</script><?php $r=5;echo $r;?> <script>")
    </script>
    

    you have to script off on when php start

    0 讨论(0)
  • 2020-12-18 17:36

    I use it like this

    $text="Example PHP Variable Message";
    echo '<script type="text/javascript">alert("'.$text.'")</script>';
    
    0 讨论(0)
  • 2020-12-18 17:40

    Have you tried this?

    alert ('<?php echo $b ?>');
    
    0 讨论(0)
  • 2020-12-18 17:42

    This worked for me :

    alert ("<?php echo $b; ?>");
    
    0 讨论(0)
提交回复
热议问题