0

我的 PHP 代码由于某种原因无法工作,我在elseif. 我真的无法弄清楚,因为我从未使用过elseif,但我在 YouTube 上看到你可以使用它,但我真的需要一些帮助来解决这个问题,但在我设置之前它运行良好$status1-2 = closedmsg1-2。你知道答案或其他方法$status1-2 = closedmsg1-2吗?我也搜索了一些“字符串替换器”或“字符串集”,但我找不到它。

<?php
//Made by Arnem\\

//\\Options//\\
$closed = 2000;
$opend = 1500;
$openmsg = '<p class=customfont>Streaming status: Online</p>';
$closemsg = '<h1 class=customfont2>Streaming is currently offline!</h1>';
$closemsg2 = '<p class=customfont>Streaming status: Offline</p>';
//DO NOT CONFIGURE UNDER THIS LINE!\\
$time = gmdate(H)+1 . gmdate(i);
if ($time>$closed)
$status1 = $closemsg;
$status2 = $closemsg2;
elseif ($time<$opend)
$status1 = $closemsg;
$status2 = $closemsg2;
else
$status2 = $openmsg;

echo$status1;
echo $status2;
?>
4

2 回答 2

2

尝试

if ($time>$closed){
$status1 = $closemsg;
$status2 = $closemsg2;
}elseif ($time<$opend){
$status1 = $closemsg;
$status2 = $closemsg2;
}else{
// are you missing $status1 here? could be why its not working
$status2 = $openmsg;
}

你少了大括号{}。唯一可以不使用它们的情况是它的单个语句 if/else。

于 2013-01-18T22:33:23.400 回答
1

您需要大括号(只有单个语句分支可以没有它们)。

if ($time>$closed) {
    $status1 = $closemsg;
    $status2 = $closemsg2;
} elseif ($time<$opend) {
    $status1 = $closemsg;
    $status2 = $closemsg2;
} else {
    $status2 = $openmsg;
}
于 2013-01-18T22:33:27.783 回答