如何显示此信息,以便颜色代码正确显示文字?这只是一个小片段,但我似乎无法让它工作。我试图把它变成一个阵列但是卡住了。
if($pclass == "c1" or "c2" or "c3" or "c4" or "c5"){
$pcolor = '<font color="#0000FF">';
$pend = '</font>';
} else {
if($pclass == "w1" or "w2" or "w3" or "w4" or "w5"){
$pcolor = "<font color='#FF6600'>";
$pend = "</font>";
} else {
if($pclass == "r1" or "r2" or "r3" or "r4" or "r5"){
$pcolor = "<font color='#00FF00'>";
$pend = "</font>";
} else {
if($pclass == "h1" or "h2" or "h3" or "h4" or "h5"){
$pcolor = "<font color='#CC00CC'>";
$pend = "</font>";
}
}
?>
<div id="top">
<h1>
<?php echo "$requestname"; ?>
</h1>
<p class="small">
<?php
echo "$player's primary class is $pcolor $pclass $pend";
echo ", $player's secondary class is $sclass";
答案 0 :(得分:0)
当您使用PHP的or
运算符时,您正在使用||
。此外,您在底部缺少两个括号,无论如何都可能搞砸了整个脚本。最后,您需要检查 每个 值的条件,而不仅仅是第一个。
<?php
if ($pclass == "c1" || $pclass == "c2" || $pclass == "c3" || $pclass == "c4" || $pclass == "c5") {
$pcolor = '<font color="#0000FF">';
$pend = '</font>';
} else {
if ($pclass == "w1" || $pclass == "w2" || $pclass == "w3" || $pclass == "w4" || $pclass == "w5") {
$pcolor = "<font color='#FF6600'>";
$pend = "</font>";
} else {
if ($pclass == "r1" || $pclass == "r2" || $pclass == "r3" || $pclass == "r4" || "r5") {
$pcolor = "<font color='#00FF00'>";
$pend = "</font>";
} else {
if ($pclass == "h1" || $pclass == "h2" || $pclass == "h3" || $pclass == "h4" || $pclass == "h5") {
$pcolor = "<font color='#CC00CC'>";
$pend = "</font>";
}
}
}
}
?>