当我在一些html代码中找到某个单词时,我试图在body标签中添加一个类。
到目前为止,我已提出:
<?php echo $this->row->description;
if (stripos($this->row->description, 'Sold')!== false) {
echo 'true';
}
?>
我可以在网页上看到“真实”的回应。所以我知道它有效,并没有显示网页上是否有“已售出”这个词。
我想做的是改变echo'true';将类“true”添加到网页的body标签的内容。
答案 0 :(得分:0)
这应该足够了:
<body class="<?php echo stripos($this->row->description, 'Sold')!==false?'true':'' ?>">