Example 3: Time Greeting

  • Modify the following example so that between midnight and 4 am the message reads "Sweet Dreams."
  • Save it on Aspen as TimeGreeting.php
  • Run your script on Aspen.
  • Example 

 

<html>

<head>

   <title>Example 3: Time of Day Greeting</title>

</head>

<body>

<center>

<h1>Example 3: Time of day Greeting</h1><hr />

<h2>

   The current hour is <? echo date("H") ?>

</h2>

<font size="+4" color="#FF0000">

 

<?

   // Assign a value to name variable

   $strName = 'Marge';

   // print time of day greeting

   IF (date("H") < 12) {

      echo 'Good morning ' . $strName;

   }

   elseif (date("H") < 18) {

      echo 'Good afternoon ' . $strName;

   }

   elseif (date("H") < 22) {

      echo 'Good evening ' . $strName;

   }

   else {

      // value of variable displayed with double quotes

      echo "Good night $strName";

   }

?>

</font></center></body></html>