php中'die()'的替代项
我有以下脚本php中'die()'的替代项,php,die,Php,Die,我有以下脚本 <?php echo "I am alive<br>"; die("I am dying<br>"); echo ("Dead"); ?> 是否有任何方法(替代/替换die())继续执行剩余脚本 编辑: 对不起,我得到了我想要的,并且投票结束了这个问题。请忽略此问题。如果要在结果返回给用户后运行脚本,请尝试以下操作: while (ob_get_level () != 0) { ob
<?php
echo "I am alive<br>";
die("I am dying<br>");
echo ("Dead");
?>
是否有任何方法(替代/替换die()
)继续执行剩余脚本
编辑:
对不起,我得到了我想要的,并且投票结束了这个问题。请忽略此问题。如果要在结果返回给用户后运行脚本,请尝试以下操作:
while (ob_get_level () != 0) {
ob_end_clean ();
}
header ("Connection: close\r\n");
header ("Content-Encoding: none\r\n");
ignore_user_abort (true);
ob_start ();
// do stuff that should be returned here
header ("Content-Length: ".ob_get_length ());
ob_end_flush ();
flush ();
// do rest here
您可以使用:
如果问题背后的动机在于错误处理,那么您可能想看看PHP中的try/catch结构
除了打印内容外,您还希望该函数做什么?die的全部目的是终止脚本。您正在寻找一个命令来终止脚本执行,而不是终止脚本执行?我有一个给你:`;`;`)你能详细说明一下你想用这个实现什么吗?是否要设置另一种处理错误的方法?
while (ob_get_level () != 0) {
ob_end_clean ();
}
header ("Connection: close\r\n");
header ("Content-Encoding: none\r\n");
ignore_user_abort (true);
ob_start ();
// do stuff that should be returned here
header ("Content-Length: ".ob_get_length ());
ob_end_flush ();
flush ();
// do rest here
<?php
echo "I am alive<br>";
trigger_error("I am dying<br>");
echo ("Dead");
?>
I am alive
Notice: I am dying in ... on line 3
Dead