Developing Webs logo
Google
Web DW-Main DW-Photoshop
Visit the message board for solutions or post a question Check out the Classes offered for free at Developing Webs Voice Chat submit a tutorial, resources, article, font for publication consideration and earn a one way link back to your site Get more specifics about the Developing Webs Voice chat room and its room members View the current news at Developing Webs alternative sites which are resources for your d3evelopment needs Join Developing Webs Chat Link to us on your web page to help support this resource! Check out Developing Webs At yahoo groups! Developing Webs Home Adobe Photoshop Tutorials Macromedia Flash Tutorials Jasc Paint Shop Pro Tutorials Adobe Illustrator Animation basics Some Basic PHP tutorials Perl Tutorials HTML Tutorials Cascading Style Sheets javascript Front Page Tutorials Macromedia Dream Weaver Tutorials dreamweaver Publishing your site, FTP, ChMod, Promotions Tools to help you create your site Free and shareware fonts to download Photographs to use in your projects Shop for your site needs Free Online classes REcommend this site to others Log in or edit your information when logged in Developingwebs Log Out Change My Account details and preferences
RSS Newsfeed
for your site
DW News
Calendar
DW Forum
Right click on button and copy shortcut

Add to My Yahoo!

Reminder
Remember to book mark this site!



Request a Tutorial

Embedding a day of the week sound, image or saying

Using the if...elseif
statements in PHP

 

<BGSOUND src=sounds/tuesday.wav>
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
day abbreviated
l   day full name
day of month or date
M month abbreviated
m number of month
Y four digit year
2 digit year
day of year out of 365
Hours in 24 hr format
Hours in 12 hr format
i   Minutes
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 "         loop=false volume=100 hidden=true>
       <BGSOUND src=".$song."> <br>        ";
 

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!

 








"Building The Web Into a Nicer Place -- One Site At A Time"
Developing Webs Group Copyright © 2001-2008 All Rights Reserved
Privacy and Legal