Php 显示Var信息

Php 显示Var信息,php,Php,我该如何显示这些信息,以便颜色代码能够正确显示文本?这只是一个小片段,但我似乎无法让它发挥作用。我试图把它做成一个数组,但被卡住了 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

我该如何显示这些信息,以便颜色代码能够正确显示文本?这只是一个小片段,但我似乎无法让它发挥作用。我试图把它做成一个数组,但被卡住了

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";
if($pclass==“c1”或“c2”或“c3”或“c4”或“c5”){
$pcolor='';
$pend='';
}否则{
如果($pclass==“w1”或“w2”或“w3”或“w4”或“w5”){
$pcolor=“”;
$pend=“”;
}否则{
如果($pclass==“r1”或“r2”或“r3”或“r4”或“r5”){
$pcolor=“”;
$pend=“”;
}否则{
如果($pclass==“h1”或“h2”或“h3”或“h4”或“h5”){
$pcolor=“”;
$pend=“”;
}
}
?>


当您应该使用PHP的
| |
操作符时,您使用的是
。此外,底部缺少两个括号,这可能会使整个脚本变得混乱。最后,您需要检查每个值的条件,而不仅仅是第一个值

<?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>";
            }
        }
    }
}
?>

我不确定你在做什么,但只回答标题:use.$pclass==“c1”或“c2”或“c3”或“c4”或“c5”总是正确的。试试$pclass==“c1”|$pclass==“c2”| |…或只是在数组中($pclass,array('c1','c2','c3','c4','c5'))也可以考虑在这些名称下定义CSS类,而不是使用字体元素。您有未终止的括号。在没有复制/粘贴错误的情况下,我没有将其固定在代码中。