最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Command in PHP equivalent to alert in javascript - Stack Overflow

programmeradmin3浏览0评论

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

Ex:

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

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

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

Ex:

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

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

Share Improve this question edited Mar 28, 2013 at 4:46 FoolishSeth 4,0312 gold badges21 silver badges28 bronze badges asked Mar 28, 2013 at 4:32 s.mujahid8s.mujahid8 1893 gold badges6 silver badges15 bronze badges 6
  • 1 There are better ways to debug both PHP and JavaScript - like using an actual debugger. – Matt Ball Commented Mar 28, 2013 at 4:35
  • I'd remend you look into firebug and fireftp to debug js and php (both are firefox extensions though they also exist in chrome) you'll find it's much easier to print your variables and call functions there. – Ryoku Commented Mar 28, 2013 at 4:36
  • FireBug will not display PHP variables If they are not being printed by PHP in the first place – Hanky Panky Commented Mar 28, 2013 at 4:39
  • i use firebug. as said by hanky panky it doesnt help – s.mujahid8 Commented Mar 28, 2013 at 4:45
  • Use an IDE such as netbeans (free) or PhpStorm (not free) that has a PHP debugger built in. – vascowhite Commented Mar 28, 2013 at 4:51
 |  Show 1 more ment

6 Answers 6

Reset to default 6

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

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

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

You can use echo, var_dump, print_r or error_log.

Just echo them

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

You can also use var_dump

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

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

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

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

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

Check out var_dump instead.

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

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

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

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.

Use this:

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

评论列表(0)

  1. 暂无评论