1. Computing

Time Based PHP Greetings

By

2 of 4

If it is AM
This bit of code would directly follow the code from the previous page.
 if ($m == "AM") 
 {
 if ($hour == 12)
 {
 echo "Good Evening!";
 }
 elseif ($hour < 4)
 {
 echo "Good Evening!";
 }
 elseif ($hour > 3)
 {
 echo "Good Morning!";
 }
 }
 
This code checks to see if the $m variable is AM. If it is AM it then checks to see what time it is using our $hour variable. If it is 12 AM (midnight) it tells the user "Good Evening!". It also says good evening if it is any time before 4AM. For times 4AM and later, it tells the user "Good Morning"!
  1. About.com
  2. Computing
  3. PHP / MySQL
  4. Step By Steps
  5. Time Based Greetings - PHP Greeting Script

©2014 About.com. All rights reserved.