PHP : Scheduled Message using Switch Statement

PHPTUTORIALS

In this tutorial you will learn on how to create a Scheduled Message with PHP and Switch Statement with these easy steps.

Note:
The date() function formats a local date and time, and returns the formatted date string.

First step, you need to declare a variable  “$dayofweek” numeric representation of the day, you can change the variable if you wanted. See the example below.

$dayofweek = date("w");

Just simply copy and paste the given code below to create HTML page.

<!DOCTYPE html> 
<html>
<head>
<title>Schedule Date</title>
<style type="text/css">
p{ font-size: 100px;
font-family: Arial;
text-align:center;
margin-top: :200px;
color: #287dcc;}
</style>
</head>
<body>
//PHP code goes here
</body>
</html>

Create Switch Statement for “$dayofweek” to select which block of code to be executed.

The  w – A numeric representation of the day (0 for Sunday, 6 for Saturday).

<?php
$dayofweek = date("w");
?>
switch ($dayofweek) {
case '0':
echo "<p>Today is Sunday !</p>";
break;
case '1':
echo "<p>Today is Monday !</p>";
break;
case '2':
echo "<p>Today is Tuesday !</p>";
break;
case '3':
echo "<p>Today is Wednesday !</p>";
break;
case '4':
echo "<p>Today is Thursday !</p>";
break;
case '5':
echo "<p>Today is Friday !</p>";
break;
case '6':
echo "<p>Today is Saturday !</p>";
break;
}
?>

Here is the complete code.

<!DOCTYPE html>
<html>
<head>
<title>Schedule Date</title>
<style type="text/css">
p{ font-size: 100px;
font-family: Arial;
text-align:center;
margin-top: :200px;
color: #287dcc;}
</style>
</head>
<body>
<?php
$dayofweek = date("w");
switch ($dayofweek) {
case '0':
echo "<p>Today is Sunday !</p>";
break;
case '1':
echo "<p>Today is Monday !</p>";
break;
case '2':
echo "<p>Today is Tuesday !</p>";
break;
case '3':
echo "<p>Today is Wednesday !</p>";
break;
case '4':
echo "<p>Today is Thursday !</p>";
break;
case '5':
echo "<p>Today is Friday !</p>";
break;
case '6':
echo "<p>Today is Saturday !</p>";
break;
}
?>
</body>
</html>

Comment down below if you have any questions 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *