如何在PHP中显示警告框?

pra*_*d22 47 html javascript php alert

我想显示一个显示PHP消息的警告框.

这是我的PHP代码:

<?php  
  header("Location:form.php");

  echo '<script language="javascript">';
  echo 'alert(message successfully sent)';  //not showing an alert box.
  echo '</script>';
  exit;
?>
Run Code Online (Sandbox Code Playgroud)

但它没有用.

Yog*_*har 129

使用此代码

echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
Run Code Online (Sandbox Code Playgroud)

问题是:

  1. 你错过了 "
  2. 应该alert不是alery

  • How can I print the value of variable in the message? (4认同)

maq*_*aqs 22

试试这个:

定义一个功能:

<?php
function phpAlert($msg) {
    echo '<script type="text/javascript">alert("' . $msg . '")</script>';
}
?>
Run Code Online (Sandbox Code Playgroud)

像这样称呼它:

<?php phpAlert(   "Hello world!\\n\\nPHP has got an Alert Box"   );  ?>
Run Code Online (Sandbox Code Playgroud)


Muh*_*bar 5

语法错误(拼写错误):

事实alert并非如此alery.


Pra*_*hak 5

echo "<script>alert('same message');</script>";
Run Code Online (Sandbox Code Playgroud)

这可能会有所帮助。