From the course: PHP for Web Designers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Changing output depending on the current time

Changing output depending on the current time - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

Changing output depending on the current time

Let's experiment with php if L structures to display different output depending on the current time. Later in this chapter we'll apply the same techniques to the Hansel and Petal website but this exercise concentrates on the code and control structures used. This page contains several paragraphs with greetings for different times of the day. What we need to do is to use php decision making structures to display the correct greeting. We also want to display the current day and the time in the 24-hour clock. Now php has an extremely useful function called date that gets the current date and time from the web server. And you can use it to generate different outputs such as the day of the week or the hour, by passing it a format string as an argument. And even though I've been using php for years I still find it difficult to remember all the formatting characters. So, let's go to the php online documentation and look at the documentation for the date function. And if we scroll down…

Contents