简体   繁体   English

用php在警报中断线

[英]break line in alert with php

<?php
function alert($msg) 
{
echo "<script type='text/javascript'>alert('$msg');</script>";
}
if(array_key_exists('btnRegisterAdmins', $_POST)) 
{ 
$fname = $_POST['FirstName'];
$lname=$_POST['LastName'];


if(empty($fname))
{
    $alertscript = "you need...<br />";
}
if(empty($lname))
{
    $alertscript = $alertscript  . "<br /> to be good...";
    alert($alertscript);
}
?>

The output was without a line drop and the tag itself appears.输出没有掉线,标签本身出现。 Which way can i solve this?我可以用哪种方式解决这个问题?

<br /> is html. <br />是 html。 Try \\n instead of the <br /> tag.尝试使用\\n而不是<br />标签。

 alert(" hi \\r\\ni am at new line")

second occurance of <br/> in your code is replaced with "/r" Try代码中第二次出现<br/>被替换为 "/r" 试试

<?php
function alert($msg) 
{

$msg = "'$msg'";  //to get message enclosed by single quotes
 echo "<script type='text/javascript'>",  //try other approach
     "alert($msg);",
     "</script>";
}

$arr = array("btnRegisterAdmins"=>1);


if(array_key_exists('btnRegisterAdmins', $arr)) 
{

    $fname = "";  //guessing no fname
    $lname="";  //guessing no lname

    $alertscript ="";

    if(empty($fname))
    {
        $alertscript = " you need...";

    }

    if(empty($lname))
    {   
        $alertscript = $alertscript  . '\r to be good...';
        alert($alertscript);

    }



}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM