How to make the background image for each day different?

0

How can I make each day of the week a different background image?

    
asked by anonymous 15.05.2018 / 04:01

2 answers

1

strftime('%A') - returns full textual representation of day Sunday até Saturday

Assign the variable $dia the value of strftime('%A') and depending on the day print the name of the image as a complement to the url of the property background-image of the style sheet

<style type="text/css">
body{background-image: url("http://dominio.com/diretorio/<?php
$dia = strftime('%A');

if($dia == 'Monday') echo 'image1';
elseif($dia == 'Tuesday') echo 'image2';
elseif($dia == 'Wednesday') echo 'image3';
elseif($dia == 'Thursday') echo 'image4';
elseif($dia == 'Friday') echo 'image5';
elseif($dia == 'Saturday') echo 'image6';
elseif($dia == 'Sunday') echo 'image7';
?>.png")}
</style>
    
15.05.2018 / 05:33
0

In this case, the solution is to change the background color, but the concept is the same for the image.

switch($day) {
    case 'Monday':
        $bg_color = "red";
        break;
    case 'Tuesday':
        $bg_color = "blue";
        break;
    case 'Wednesday':
        $bg_color = "blue";
        break;
    case 'Thursday':
        $bg_color = "gray";
        break;
    case 'Friday':
        $bg_color = "yellow";
        break;
    case 'Saturday':
        $bg_color = "green";
        break;
    case 'Sunday':
    default:
        $bg_color = "black";
        break;
}

echo "<div style='background-color:$bg_color'>Welcome to my Homepage</div>";

a>

    
15.05.2018 / 04:22