home—lects—exams—hws
breeze (snow day)
hw01
hw01: A first php program
Due Sep.07 (Wed) 17:00.
I'll grade by visiting
https://php.radford.edu/~yourUserId/itec325/hw01/hw01.php.
If I can't visit that file, you won't get any credit!
Do not change the file after the due-date;
instead make a copy of the directory1
if you want to make changes later.
-
Write a php function string pluralize( int $nums, string $noun )
which returns a user-friendly version of a number+noun:
pluralize( 3, "t-shirt" ) === "3 t-shirts".
We'll use this function on future web-pages, when (say) confirming somebody's order.
-
Be sure to include at least three test cases, each covering a different situation.
(The noun will never be the empty string, so you don't even need to check for that.)
(You may use the same bare-bones test function as used in lect01c.html.
-
You can presume that a plural is always formed by just adding “s” to any word.
(Extra credit, open-ended: incorporate more-correct rules about how plurals are formed in English.)
You should run your php program locally to make sure it works and passes all your test cases.
-
Modify your program so that it prints out a (bare-bones) web page,
including three pieces of text which are generated by calling your function
(e.g. “99 bottles of rootbeer on the wall”).
Make your code accessible on the web at
https://php.radford.edu/~yourUserId/itec325/hw01/hw01.php.
-
Finally, to help me grade,
finish your web page with a h3 header mentioning
your program's name (~yourUserId/hw01/hw01.php)
and then calling
show-source( 'hw01.php' );.
Note that this function prints a large amount of html
(which you can watch scroll by, if you run your program on the command-line with php hw01.php).
-
Extra credit:
-
Have two files, hw01/hw01.php which prints a short web page
(but doesn't show its own source-code),
and a second file hw01/hw01-sources.php which
shows source-code of hw01.php, along with a link to that page
(perhaps as part of an h3 tag).
-
Read about filemtime, and also show the file's last-modified time.
-
Read about the date format function,
and show the file's last-modified time in a human-friendly format.
Note: you'll need to call ini_set('date.timezone','America/New_York');
before you can call filemtime.
-
You now have two files, so make this one show the source of both of them!
Use hr to separate the two source-listings.
(Of course, still include links, file-modified times, etc. for each file.)
-
Write a function which takes any file name,
and prints out the file's source along with the file's name (as a link to that file),
and its last-modified time,
separated nicely (e.g. using h3 and/or hr tags).
Re-factor hw01-sources.php to call this function.
1
The unix command cp -pR existingDir/ newCopy
will Recursively copy a file, preserving the file-times.
↩
home—lects—exams—hws
breeze (snow day)