douqie6454 2016-11-07 22:18
浏览 87

PHP返回后停止HTML输出

I have a function that returns two values based on conditions, in the page that the function array is being called there is html below which outputs onto the screen:

function submitMessage($user) {
if (!$user) {
$a = "Message A";
$b = "Message B";
return array($a, $b);
}
else {
$a = "Message C";
$b = "Message D";
return array($a, $b);
}

On the page:

$message = submitMessage($username);

<div class="r-box box-shadow">
  <h4 class="text-center weight-700"><?php echo $message[0];?></h4>
    <p><?php echo $message[1];?></p>
</div>
//more html below etc

What I want is for the html output to stop after what is returned from the first part of the IF statement. Something like:

function submitMessage($user) {
if (!$user) {
$a = "Message A";
$b = "Message B";
return array($a, $b);
exit();
//would like the output to stop if this is met.
}
else {
$a = "Message C";
$b = "Message D";
return array($a, $b);
}

I tried adding the exit like above but the HTML still gets sent to the screen. Is it possible to stop the output of HTML if the first part is met?

  • 写回答

2条回答 默认 最新

  • dtm37893 2016-11-07 22:25
    关注
    <div class="r-box box-shadow">
      <h4 class="text-center weight-700"><?php echo $message[0];?></h4>
      <p><?php echo $message[1];?></p>
    </div>
    <?php  // if $message[1] is defined and not empty, exit
      if ((isset($message[1])) && (!empty($message[1]))){die();} ?>
    
    //more html below etc
    
    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接