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 - PHP Tutorial
From the course: PHP for Web Designers
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
How PHP makes decisions3m 30s
-
(Locked)
Changing output depending on the current time9m 1s
-
(Locked)
Adjusting the server's time zone8m 57s
-
(Locked)
Displaying an up-to-date copyright notice6m 18s
-
(Locked)
Challenge: Displaying an image of the month2m 15s
-
(Locked)
Solution: Displaying an image of the month5m 12s
-
(Locked)
Understanding what PHP treats as true and false2m 57s
-
(Locked)
-
-
-
-
-