0

I am trying to add a class to the body tag when php finds a certain word within a bit of html code.

So far I have come up with:

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

I can see the 'true' being echoed on the web page. So I know it's working and it doesn't show if the word 'sold' is not on the web page.

What I want to do is change echo 'true'; to something that adds the class 'true' to the body tag of the web page.

2
  • 1
    You can do something like $append_to_body = 'true';, then in your body tag add class="<?php echo $append_to_body?>"
    – scrowler
    Commented Oct 21, 2013 at 2:05
  • Is not clear what you want, but @scrowler is right Commented Oct 21, 2013 at 2:11

1 Answer 1

0

This should be enough:

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.