Good day guys! I have another code snippet for you using the switch case statement in php. This code will get the current computer day (Monday, Tuesday, etc.) and will change the background color of the html page. Here are the colors that correspond in each day:
Monday – red
Tuesday – yellow
Wednesday – blue
Thursday – orange
Friday – green
Saturday – pink
Sunday – black
PHP Code for changing background base on day in php
<!DOCTYPE html>
<html>
<head>
<title>Change Background</title>
</head>
<?php
date_default_timezone_set("Asia/Manila");
$day=date('l');
echo "<h1>Today is $day</h1>";
switch($day)
{
case "Monday":
echo "<body style='background:red'";
break;
case "Tuesday":
echo "<body style='background:yellow'";
break;
case "Wednesday":
echo "<body style='background:blue'";
break;
case "Thursday":
echo "<body style='background:orange'";
break;
case "Friday":
echo "<body style='background:green'";
break;
case "Saturday":
echo "<body style='background:pink'";
break;
case "Sunday":
echo "<body style='background:black'";
break;
}
?>
</body>
</html>
No comments:
Post a Comment