Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
停止包含整个PHP脚本(而不是HTML)的if子句_Php_Exit - Fatal编程技术网

停止包含整个PHP脚本(而不是HTML)的if子句

停止包含整个PHP脚本(而不是HTML)的if子句,php,exit,Php,Exit,我已经有这个问题大约一个小时了,并且在互联网上搜索答案。我查看了PHP文档,四处查看,搜索了一下,什么都没有 不管怎么说,我的问题是,在我尝试验证某个东西(它是错误的)之后,如果我使用exit它还将在之后停止HTML。下面是我要说的: if ($_POST['exampleEmail'] == "") { echo "Please enter an e-mail."; //Now I want only the PHP script to stop, however... exi

我已经有这个问题大约一个小时了,并且在互联网上搜索答案。我查看了PHP文档,四处查看,搜索了一下,什么都没有

不管怎么说,我的问题是,在我尝试验证某个东西(它是错误的)之后,如果我使用exit它还将在之后停止HTML。下面是我要说的:

if ($_POST['exampleEmail'] == "")
{
    echo "Please enter an e-mail."; //Now I want only the PHP script to stop, however...
    exit; //If I use exit, then the HTML after this script (footer) doesn't show.
}
如果有人能帮忙,请帮忙。我试过使用break,但没有用,因为它只用于循环和开关

如果有更好/更正确的方法(如果这是错误的方法,请简单地纠正),请分享。我以前也遇到过这个问题,当时我只是使用了exit


谢谢。

如果块:

$execute = true;

// HTML here...
if (empty($_POST['exampleEmail'])) {
    echo "Please enter an e-mail.";
    $execute = false;
}
// HTML here...
if ($execute) {
    // do stuff only if execute is still true.
}
// HTML here...

既然这对您有效,我建议您进行一些研究,以分离您的演示和逻辑。关于这个主题有很多教程和博客,你只需要开始搜索。

你应该在PHP中使用if语句。

if ($_POST['exampleEmail'] == "")
{
    echo "Please enter an e-mail.";
    $stop_script = true; //stop the script
}
else    $stop_script = false; //or continue the script

if($stop_script === false)
{
    //php scripts
}

//html

改用
break
。但是如果首先涉及到这个用例,您可能会遇到结构问题。

我相信您可以使用
返回
(或者可能是
中断
,我忘了)语句退出当前的php
if
循环。也许你也可以分配一个变量并检查该变量是否存在,以确定是否要执行任何进一步的检查?是的,谢谢大家^ ^我告诉邮报给我发送新回复的电子邮件,但我猜它忘了O.oThanks!事实上,我在浏览互联网时发现了类似的方法,但我想我忘了。再次感谢!哦,关于逻辑,这类似于游戏开发,事件处理->逻辑->渲染,对吗?如果是这样,我有一个基本的设置:)是的,它是类似的。在web开发中,模型-视图-控制器体系结构通常用于此目的。