PHP 中的命令相当于 javascript 中的警报

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15674327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 01:38:28  来源:igfitidea点击:

Command in PHP equivalent to alert in javascript

phpjavascriptdebuggingalert

提问by s.mujahid8

I use the 'alert' command in javascript's to check values of variables so as to debug my code. but i cant find any such command in PHP which shows a simple popup box like the alert command. im new to PHP.
is there something i dont know?

我使用 javascript 中的“警报”命令来检查变量的值,以便调试我的代码。但我在 PHP 中找不到任何这样的命令,它显示一个简单的弹出框,如警报命令。我是 PHP 新手。
有什么我不知道的吗?

Ex:

前任:

$username=$_REQUEST["username"];
$password=$_REQUEST["password"];

Here i just want to find out what values are coming in those variables. if it was javascript, i would simply use alert (username) and alert (password). how to do it in php? thank you.

在这里,我只想找出这些变量中的值。如果是 javascript,我会简单地使用警报(用户名)和警报(密码)。如何在 php 中做到这一点?谢谢。

采纳答案by Hanky Panky

Just echo them

只是回应他们

echo "Username:".$username;
echo "<br>";
echo "Password:".$password;

You can also use var_dump

你也可以使用var_dump

PHP is a server side language and does not provide client side functionality like JavaScript alert()

PHP 是一种服务器端语言,不提供像 JavaScript 那样的客户端功能 alert()

回答by Sriniwas

PHP does not have any function to display a pop-up..

PHP 没有任何显示弹出窗口的功能。

However u can achieve that by writing javascript inside php like this

但是你可以通过像这样在 php 中编写 javascript 来实现

 echo "<script type='text/javascript'>alert('Username'".$username.");</script>";
 echo "<script type='text/javascript'>alert('Password' ".$password.");</script>";

回答by Ricardo Alvaro Lohmann

You can use echo, var_dump, print_ror error_log.

您可以使用echovar_dumpprint_rerror_log

回答by Mark Parnell

PHP is server-side, not client-side, so to expect it to behave like JavaScript is somewhat strange.

PHP 是服务器端,而不是客户端,所以期望它像 JavaScript 一样运行有点奇怪。

Check out var_dumpinstead.

来看看吧var_dump

If you really want a JS alert, you could always create a PHP function along these lines:

如果你真的想要一个 JS 警报,你总是可以按照以下方式创建一个 PHP 函数:

function debugAlert($var)
{
    echo '<script type="text/javascript">';
    echo 'alert("'.$var.'")'; 
    echo '</script>';
}

Then to output your data, just call debugAlert($username)etc.

然后输出您的数据,只需调用debugAlert($username)等。

That's a very simplistic version - in reality you'd need to escape quotes in the variable value and also include some logic to handle if the variable is an array or object, but it should get you moving in the right direction.

这是一个非常简单的版本 - 实际上,您需要在变量值中转义引号,还需要包含一些逻辑来处理变量是数组还是对象,但它应该让您朝着正确的方向前进。

回答by MKV

Just use print_r($_REQUEST). Its displays all the values array('username'=>'','password'=>'');

只需使用print_r($_REQUEST). 它显示所有值array('username'=>'','password'=>'');

or echo the value echo $username; and echo $password;

或 echo 值 echo $username; 并回显 $password;

echo "<script type='text/javascript'>alert('username and password'+$username+' & '+$password)";

回答by user9307051

Use this:

用这个:

echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';