当 PHP 在网页中找到单词时,将类添加到正文标记


Add Class to body tag when PHP finds a word within a web page

当 php 在一点 html 代码中找到某个单词时,我正在尝试在正文标签中添加一个类。

到目前为止,我已经想出了:

<?php echo $this->row->description;
if (stripos($this->row->description, 'Sold')!== false) {
    echo 'true';  
} 
?>

我可以看到"真实"在网页上得到回应。所以我知道它正在工作,并且它不会显示网页上是否没有"已售出"一词。

我想做的是将echo 'true'更改为将类'true'添加到网页的正文标签中的东西。

这应该足够了:

<body class="<?php echo stripos($this->row->description, 'Sold')!==false?'true':'' ?>">