尝试执行其他操作以回显此错误。
我曾尝试使用htmlentities,但仍然相同
if ($row["Status"] == 'ONLINE') {#
echo htmlentities('<span class="label label-success label-rounded">Online</span>');
echo '<span class="label label-success label-rounded">Online</span>'
} else {#
echo htmlentities('<span class="label label-danger label-rounded">Offline</span>');
echo '<span class="label label-danger label-rounded">Offline</span>'
}
答案 0 :(得分:1)
如果我们希望if
处于联机和脱机状态,我们可以为HTML定义两个字符串,那么我们将有一个$online_html = '<span class="label label-success label-rounded">Online</span><span class="label label-success label-rounded">Online</span>';
$offline_html = '<span class="label label-danger label-rounded">Offline</span><span class="label label-danger label-rounded">Offline</span>';
if ($row["Status"] == 'ONLINE') {
echo $online_html;
} else {
echo $offline_html;
}
语句,也许类似于:
if ($row["Status"] == 'ONLINE') {
echo '<span class="label label-success label-rounded">Online</span><span class="label label-success label-rounded">Online</span>';
} else {
echo '<span class="label label-danger label-rounded">Offline</span><span class="label label-danger label-rounded">Offline</span>';
}
或者:
$html['ONLINE'] = '<span class="label label-success label-rounded">Online</span><span class="label label-success label-rounded">Online</span>';
$html['OFFLINE'] = '<span class="label label-danger label-rounded">Offline</span><span class="label label-danger label-rounded">Offline</span>';
echo $html[$row["Status"]];
或者完全跳过if if:
MERGE
答案 1 :(得分:0)
避免混淆单引号和双引号等的一种方法是记住php是一种模板语言。
如果您要打印某些内容,则意味着您已经完成了所有逻辑,现在只输出视图:即,您正在编写注入PHP的HTML,用于循环或条件输出。
例如,
npm install fullcalendar@3.6.1
或者,更好的是,不要重复自己:
// end of php logic
?>
<!— html output follows —>
<?php if($row[‘Status’] == ‘ONLINE’): ?>
<span class="label label-success label-rounded">Online</span>
<?php else: ?>
<span class="label label-danger label-rounded">Offline</span>
<?php ending; ?>
答案 2 :(得分:0)
您可以将html条目放在php
代码之外。
<?php
if($row["Status"] == 'ONLINE') {
?>
<span class="label label-success label-rounded">Online</span>
<?php
}
else{
?>
<span class="label label-danger label-rounded">Offline</span>
<?php
}
?>