Setting a greeting based on user's time (Good morning, good afternoon…)

后端 未结 6 1960
孤街浪徒
孤街浪徒 2021-02-02 11:13

Can anyone extrapolate on how to implement a basic \"good evening\" or \"good morning\" based on the user\'s time setting?

Perhaps PHP will fetch the server time, but I

6条回答
  •  北海茫月
    2021-02-02 11:49

    $hour      = date('H');
    
    if ($hour >= 20) {
        $greetings = "Good Night";
    } elseif ($hour > 17) {
       $greetings = "Good Evening";
    } elseif ($hour > 11) {
        $greetings = "Good Afternoon";
    } elseif ($hour < 12) {
       $greetings = "Good Morning";
    }
    echo $greetings;
    

提交回复
热议问题