1. Home
  2. Computing & Technology
  3. PHP / MySQL

Time Based PHP Greetings

By , About.com Guide

4 of 4

Full Code

This is the full code for the script learned on the previous pages.
<?php

$b = time();

$hour = date("g",$b);
$m = date ("A", $b);

if ($m == "AM")
{
if ($hour == 12)
{
echo "Good Evening!";
}
elseif ($hour < 4)
{
echo "Good Evening!";
}
elseif ($hour > 3)
{
echo "Good Morning!";
}
}

elseif ($m == "PM")
{
if ($hour == 12)
{
echo "Good Afternoon!";
}
elseif ($hour < 7)
{
echo "Good Afternoon!";
}
elseif ($hour > 6)
{
echo "Good Evening!";
}
}

?>
Explore PHP / MySQL
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. Time Based Greetings - PHP Greeting Script

©2009 About.com, a part of The New York Times Company.

All rights reserved.