Welcome, guest | Sign In | My Account | Store | Cart

this is a script that changes the colour of the background to the day of the week, the code uses if and elseif...

PHP, 42 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php

// A list of the days of the week. 
$name_day = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

foreach ($name_day as $name);

{
  if ($name == "Sunday") 
      { // if day is Sunday background color is - Green.
        $background_color = "Green";
      }
  elseif ($name == "Monday") 
      {
       $background_color = "#ff9966";
      }
  elseif ($name == "Tuesday")  
      {
       $background_color = "#cccc33";
      }
  elseif ($name == "Wednesday")  
      {
       $background_color = "#999900";
      }
  elseif ($name == "Thursday") 
      {
       $background_color = "#66cc33";
      }
  elseif ($name == "Friday") 
      {
       $background_color = "#cc0000";
      }
  elseif ($name == "Saturday")  
      { // if day is not Sunday, but day is Saturday background color is - Purple.
       $background_color = "ff66ff";
      }
}   

$name_of = date("d-l-y"); // date, day, year.

echo "$name_of";
?>

1 comment

Victor Shermadevi 13 years, 1 month ago  # | flag

Great job Senor Fenech! This will be useful in creating my calendar widget for my sie. Thanks a lot and keep up the great work.

Created by Jonathan Fenech on Thu, 5 Mar 2009 (MIT)
PHP recipes (51)
Jonathan Fenech's recipes (6)

Required Modules

  • (none specified)

Other Information and Tasks