1

我想在甜蜜警报中显示 PHP 变量但找不到解决方案,我浏览了甜蜜警报 2 的文档但找不到任何东西。谁能帮我?

这是我的代码

$name = "xyz";

//sweetalert code
echo "<script>";
echo 'setTimeout(function () { swal("Greetings $name!","Thank you for adding your business details.<br>Our admin team will review the same and will publish shortly..!","success");';
echo '}, 100);</script>';
4

2 回答 2

2

只需要切换引号:

echo "setTimeout(function () { swal('Greetings $name!','Thank you for adding your business details.<br>Our admin team will review the same and will publish shortly..!','success');'";

或者,另一种选择,在字符串中连接变量:

echo 'setTimeout(function () { swal("Greetings ' . $name . '!","Thank you for adding your business details.<br>Our admin team will review the same and will publish shortly..!","success");';

当你在 echo 中包含一个变量时,你需要使用"

"知道和'另一个SO 答案之间的区别


于 2017-09-08T09:46:18.283 回答
0

您需要连接它,尝试使用以下内容:

echo 'setTimeout(function () { swal("Greetings"'.$name.'"!","Thank you for adding your business details.<br>Our admin team will review the same and will publish shortly..!","success");';
于 2017-09-08T09:48:56.650 回答