我想在甜蜜警报中显示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>';
答案 0 :(得分: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 Answer
答案 1 :(得分: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");';