PHP Script: Changing Background Based on the Day

Unknown Thursday, November 17, 2011
PHP script that will be discussed this time used to change the background of our web pages according to day. For example on Monday, we want the background color Yellow, Tuesday, Red, and so on. Interested? Please continue reading.
Actually a simple principle. We will use branching statements or if else to do it.


The logic is like this. PHP script we'll find out the name today by using date functions (see the example of another script that uses this function when calculating the time and calendar calculations). Well, then today's name will be matched using the command menampilkanwarna if else and then we want according to the results of matching the name of the day.
The full PHP script is like this:

$today = date("l");
print("$today");
if($today == "Sunday")
{
$bgcolor = "#FEF0C5";
}
elseif($today == "Monday")
{
$bgcolor = "#FFFFFF";
}
elseif($today == "Tuesday")
{
$bgcolor = "#FBFFC4";
}
elseif($today == "Wednesday")
{
$bgcolor = "#FFE0DD";
}
elseif($today == "Thursday")
{
$bgcolor = "#E6EDFF";
}
elseif($today == "Friday")
{
$bgcolor = "#E9FFE6";
}
else
{
// hari terakhir tentusaja hari Sabtu (Saturday) kan?
$bgcolor = "#F0F4F1";
}
print("\n");
?>

This script just change the background color, you can customize your own contents

Hopefully useful.
Warmest regards.
Blogger Template by BlogTusts Sticky Widget by Kang Is Published by GBT.

No comments:

Post a Comment