1. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    Im very new to php and I havent gotten hold of the syntax yet.

    I wanted to make a function that will print "Good Morning" on the screen if the $hour string is less than 12, "Good Afternoon" if less than 18, and "Good Evening" if anything else..

    This is my code.


    $hour = date("h");

    if ($hour < 6)
    print "Good Early Morning";

    elseif ($hour < 12)
    print "Good Morning";

    elseif ($hour < 18)
    print "Good Afternoon";

    print "Good Evening";



    Does anyone know what Im doing wrong?
  2. #2
  3. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    Hi Samuel,

    3 Suggestions:

    1) Get rid of that "endif". That will cause a parse error.

    2) Use a capital H in date(). Lowercase returns a value 1-12. You need 0-23.

    3) If this app will be running on the web, you should do this on the client side with JavaScript instead of on the server with PHP. If your server is in Toronto, but your user is in Damascus, this will show the wrong greeting anyway.

  4. #3
  5. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    Thanks Chris, It would be pretty funny if it said Good Evening to someone in the Middle East or other places when its Morning for them.

Similar Threads

  1. Uploading Files
    By vivekjain in forum ASP Programming
    Replies: 0
    Last Post: February 16th, 2004, 11:21 PM
  2. database access using thread
    By padmini in forum Visual Basic Programming
    Replies: 3
    Last Post: February 6th, 2004, 12:38 AM
  3. function within function error
    By Germanjulian in forum PHP Development
    Replies: 1
    Last Post: January 7th, 2004, 04:08 AM
  4. passing a form's select name into a javascript function
    By kilt88 in forum JavaScript Development
    Replies: 1
    Last Post: January 6th, 2004, 01:12 PM
  5. Code Benchmarking Tests
    By infamous41md in forum C Programming
    Replies: 4
    Last Post: December 27th, 2003, 04:15 PM

IMN logo majestic logo threadwatch logo seochat tools logo