University of Washington, CSE 190 M

Lab 3: PHP

Except where otherwise noted, the contents of this document are Copyright 2010 Marty Stepp and Jessica Miller.

original lab idea and code by Brian Le; revised by Marty Stepp

Valid XHTML 1.1 Valid CSS!

Basic lab instructions

Today's lab exercises

Brian has written a page named music.html to display his MP3s. He has already written the basic HTML and CSS code. But the HTML is redundant, and he must manually edit it every time he adds songs to his collection.

In this lab, you will turn this page into a dynamic PHP page in a file named music.php that removes redundancy and dynamically lists the MP3s on the computer. Download the HTML file below to get started:

Exercise : Basic Hello World (~5 min)

(See example screenshot on next slide.)

Let's turn music.html into a PHP page and make sure you can see PHP output on Webster.

Exercise , output

The start of your page should look like this when you are done:

expected output

Exercise : Link Redundancy (~10 min)

(See example screenshot on next slide.)

See book Chapter 5 or the lecture slides/examples if you can't remember PHP syntax.

Exercise , output

The start of your page should look like this when you are done:

expected output

Exercise : List MP3 Files (~15 min)

(See example screenshot on next slide.)

Currently the page hard-codes the list of MP3 file names. Let's change it to read the file names dynamically from the server's hard drive.

Exercise , output

Your MP3 list should look like this when you are done:

expected output

Exercise : MP3 Formatting (~10 min)

(See example screenshot on next slide.)

Now let's format the MP3 links to look like the original hard-coded ones.

Exercise , output

Your MP3 list should look like this when you are done:

expected output

Exercise : Playlist Contents (~15 min)

(See example screenshot on next slide.)

Add code to display the contents of .m3u playlists. A playlist is just a text file containing a list of song file names, one per line. It can also have comment lines that begin with # . Example:

#EXTM3U
#EXTINF:177,Paul Dateh & Oren Yoel - Be More
be-more.mp3
#EXTINF:291,Christopher Toy - Just Because
just-because.mp3

Use the strpos function to search a line for a substring.

Exercise , example

Your page should look like this when you are done (scroll to the bottom):

expected output

Exercise : Song Size Info (5-10 min)

(See example screenshot on next slide.)

Display each MP3's size in appropriate units. Use the filesize function.

If displaying kb or mb, show the value as a whole number.

Exercise , example

The songs should look like this on the page when you are done:

expected output

Exercise : (h4x0rz only): Ordering/Sorting

If you finish them all...

If you finish all the exercises, you can add any other content or code you like to your page.

If the lab is over or almost over, check with a TA and you may be able to be dismissed.

Great work!