How can i change background color in php?

I have a standard html page so:


..
.
..
and so on

and i have a php script linked to that html page with:

if blablabla {

change background color;
}

does anyone know how to change the background color of my page if the conditions in the if statement are met?

I hope i made this clear, if not, please say which bit is unclear.

Thanks for any help in advance

asked Mar 29, 2011 at 15:59

1

put your tag inside the if else

if blablabla {

 echo '';
}
else {
 echo '';
}

answered Mar 29, 2011 at 16:04

Shakti SinghShakti Singh

82.1k20 gold badges132 silver badges150 bronze badges

2

It's not necessarily great practice, but it should get the job done:

if [ your_conditional ] {
  $styleBlock = sprintf['
    
       body {
         background-color:%s
       }
    
  ', $yourColor];
  echo $styleBlock;
}

One good [?] thing about this is that with this technique, you can put your if statement anywhere - it'll act on the body tag regardless of where you put it.

One caution: if you have additional style rules for the body tag's background color farther down your page, those will take precedence over the one from your if statement.

answered Mar 29, 2011 at 16:09

Kyle HumfeldKyle Humfeld

1,8373 gold badges23 silver badges28 bronze badges

here is code that i whant to change background of body

Chủ Đề