How to change background of an image in CSS code with PHP

2

I would like to know how I can do the following to change the background of a background image img in css by day of the week, or from Monday to Sunday so that for each day of the week a different image in the background appears in the background css code how can i do this using php.

Note: In case I need this background to be applied to a div as class because these backgrounds will be used in a skin. Thank you in advance for helping me.

    
asked by anonymous 14.06.2015 / 22:58

1 answer

2

To know the number of the day of the week you can use date() like this:

$ds= date("w");

Sunday is number 0 , second 1 , and so on. This way you can have an array with the images you want to use:

$imagens = array('domingo.jpg', 'segunda.jpg', etc...);

and then in your code:

<div style="background-image: url(<?php echo $imagens[$ds]; ?>)"></div>

You could also have a class for each day already prepared in CSS, and in the PHP array you have the names of those classes. In this case you would use:

<div class="<?php echo $imagens[$ds]; ?>)"></div>
    
14.06.2015 / 23:18