| In PHP you can query for the date, time, year,
day of the year and so forth. To output the date, you simply write the
statement as follows: echo date("D M Y H:i:s");
This statement will give you the day, month year, hour:minutes:seconds at
this exact time.
If you would like to write a script that gives you the day of the week,
we can simply use the date() statement to output the date(D) in our HTML. We
can do that with any of the date functions. Below is a list of date
functions that can be used:
|
parameter |
what it stands for |
|
D |
day abbreviated |
|
l |
day full name |
|
d |
day of month or date |
|
M |
month abbreviated |
|
m |
number of month |
|
Y |
four digit year |
|
y |
2 digit year |
|
z |
day of year out of 365 |
|
H |
Hours in 24 hr format |
|
h |
Hours in 12 hr format |
|
i |
Minutes |
|
s |
Seconds |
- In this activity there are 7 images, one for each day, names monday.gif, tuesday.gif, wednesday.gif etc. Download the images to use to
complete this from here
- There are 7 sounds to complete this tutorial, also located here.
1. Open up your PHP editor. Set up your normal html tags for the head ,
end of head, and body end of body, etc.
2. Insert your PHP tags for opening of your script and closing of the
script:
3. We will use the If... else if statement to determine what today is.
this will test the date one at a time, and set the sound name and picture
name acording to the weekday.
if (date("l")=="Monday") {
$song="monday.wav";
$image="monday.jpg";
}
4. We can go further and give an alternative so that if the
statement is not true, it will give an alternate response. In this case we
can test to see if the day is Monday.
elseif (date("l") == "Tuesday") {
$song="tuesday.wav";
$image="tuesday.jpg";
}
5. We will need to go beyond, because the rest of the week, both
statements are false. I can write one per each day of the week through
Saturday.
6. Once you have your script through saturday, you can put your last
alternative as an else echo statement :
else {$song="sunday.wav";
$image="sunday.jpg";
}
7. We need output statements so that the page displays our image and
plays our sound. These are echo statements, where the HTML is written in
quotes and the variable is outside of the quotes so it get relaced with the
day filename.
echo " ";
echo "
8. Close your PHP statement and decorate your page. above and below the
info. Upload your info to a PHP server and you are on your way!
|