在 Sweet alert 2 中传递 PHP 变量
Passing PHP variabe in Sweet alert 2
我想在 sweet alert 中显示 PHP 变量但无法找到解决方案,我浏览了 sweet alert 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>';
只需要切换引号:
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
你需要连接它,尝试使用以下:
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");';
我想在 sweet alert 中显示 PHP 变量但无法找到解决方案,我浏览了 sweet alert 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>';
只需要切换引号:
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
你需要连接它,尝试使用以下:
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");';