MMDT1146 PHP Programming
Week 4


Week 4

General Notes:

  • For PHP documentation go to http://www.php.net/manual/en/ and find the area you are looking for.
  • When there is an error when running your script, look on the line mentioned or the previous code line above.
  • Make sure for every left brace { there is a corresponding right brace }.
  • Validate your resulting pages.  Run your script.   Save the page to your hard drive.  Go to http://www.w3.org/ and run the HTML validator by uploading your file.   There is also a validator available at http://www.htmlhelp.com.

Function Notes:

  • Pass everything the function needs in with the arguments.
  • Generally functions should not print to the screen.  This is for purposes of reusability.
  • Instead, the function should pass all results out through the return of a variable, string, or array.

File Includes:

  • Somes books suggest the extension name of ".inc" to be used for an include.  I have tried that, but I found that using an extension of ".html" for static pages or ".php" for dynamic includes to be a better choice.  Reason being that code editors, such as Dreamweaver, only color highlight and indent code if it thinks the text is code when the .html, or .php extensions are used.
  • Remember, an include is ONLY a snippet of html code.  Therefore by itself, an include file does not have the proper opening and closing html tags.
  • I use an include on each one of my syllabi pages to display the disability statement.

Lab 4

This lab is to test your knowledge of being able to use functions, date & time functions, and file includes.

Create a subfolder on your web server named "lab4".  (This may already be done for you from doing the in class exercises.)

Under the subfolder "lab4" that you just created, you will need to create several files.  The names are of your choosing.  In my example, I called them "lab4.php", "lab4results.php", "utilities.php", and "footer.inc.php".

The lab must contain several items.  Your resulting output should like similar to this.

Title your pages.
Put captions on the top of your pages.
Add a background.

On the first page:

Take your original lab3 form that you did last week and slightly modify it.  Add two groups of radio buttons to select ascending or descending sort orders.

Create a separate php file:

This file (I named mine "utilies.php") needs to contain at least one function.  The bulk of the code for this function comes from last week's assignment.  I provided a nifty function for you called clean_string that cleans up most of the input string.   You should call clean_string from the other functions. You need to make clean_string more robust, so if there are hidden or other odd characters in the string, it gets fixed appropriately.

Create a footer page:

I named mine "footer.inc.php". Change the date/time format to something different than what we did in class.
Also put a copywriter on the page.

On the results page :

Call your functions that you created.  You will need to "require_once("utilities.php");" once in order to call your functions.

Print the total number of seconds it took to execute each piece of the exercise.   Hint:  you will need the microtime(true) function.

Include your footer page on both the form page and the results page.

Assignment is due 1 week from when it was assigned.  50% penalty if late.

MMDT 1146 Lab 4
Grading Criteria
Date:
Possible
Points
20
Your
Points
20
Pages are titled, captioned, and have a background. 1 1
The form page has radio buttons added. 2 2
A utilities page has been created that contains the clean string and clean array functions. 5 5
Function word alpha sort works as in the previous week plus does descending order as well. 3 3
Function word frequency sort works as in the previous week plus does descending order as well. 3 3
Times required to execute each piece is displayed. 3 3
Include file contains a date and copyright and is included on both the form and the results page. 3 3