Assignment #5a
PHP Dictionary
Level of Difficulty: Hard
Potential Points: 108 out of 100
You are to create a PHP script that constructs a dictionary accessible from
a web form built from this text file. Read the text
file into an associative array. A user should be able to input a word, and if
found, view the word along with its corresponding definition. The output (HTML)
and logic (PHP) must be an exact recreation of this dictionary
script.
Grading
- Branching - There should be four separate printouts: the default page when
it's first loaded (without submission), the submitted page with appropriate
error message (missing word as input or file was not opened), the 'success'
page with the returned word and definition, and a 'word not found' page (the
search term was not found in the dictionary). Obviously, you're going to load
an array with the terms and corresponding definitions; be sure that you only
load the array when the user presses submit. Don't worry about when the user
presses enter when the textbox is highlighted. I'm not looking for other error
handling messages other than what I've mentioned here.
- Matching HTML Output - The rendered HTML must look exactly like the displayed
dictionary script (Don't worry about making the unrendered HTML match). Please
notice how the original query is printed (with more than one word).
- Validity - Notice that all printouts are transitionally valid, not just
the default page. Remember that well-formedness is a requirement of validity.
- Form Element Validation - Part of the branching component requires form
validation (or checking for required form elements). The form elements should
be present as variables once the form is submitted; if the query is missing,
print out the appropriate error message. If it is present, reprint the query
in the textbox. If the user inputs two or more words (delimited by space(s)),
use the first word. Do not use the same form element, name attribute values
used in my dictionary script...come up with your own.
- Legibility - Make sure you put in comments and indentions (if-else statements)
to make the PHP code more ledgible. PHP statements should not be too long.
Also, be sure add newlines and tabs to make your unrendered HTML ledgible.
You don't have to comment on every line of code; instead, try to group comment
descriptions.
- Algorithm Logic - Add the algorithm (recipe) to the header comment...your
program code should correspond to the logic of this algorithm.
- Image - An image you create must be apparent on all pages. The image should
be created in Photoshop, contain the phrase "[yourname]'s Dictionary
Search", and incorporate at least one filter (Be sure to make the filter
visible/apparent).
Specifications
- Use one script/file. The form should submit to itself.
- The name of the terms text and image files must be stored in a separate
php document and imported for use within the main script.
- You should have one single-line textbox and a submit button.
- Make the search case-insensitive; if I search for the terms 'Root' and 'root',
I should get the same result.
- The terms should be collected and stored dynamically from the text file...not
in the program itself. I should be able to use another text file, with a different
set of words, in the same format, and search it.
- The 'success' page should contain the time search was executed somewhere
on the bottom of the screen. (Hint: use the date function.)
- Only use PHP and HTML tags...no JavaScript or other client-side technology.
- Use your own code! You may use the examples from the class and examples
but do not copy and paste. Do not use already existing code on other sites...I'm
aware of what is available.
Notes
- We have not discussed file handling in the course. We only talked about
briefly about associative arrays. This partially the reason why this assignment
is rated 'hard'. I only recommend that students with practice and/or experience
with PHP try this assignment.
- Send the form data using the POST method...makes things much simplier.
- You will not need to iterate (foreach) through the loaded term array.
- As a hint, some of the functions used may include: strtolower, fopen,
feof, split, & in_array.
- What happens when you put in one or more spaces before the query?
- As always, note that specifications are requirements.
- Many people get points deducted for doing more than what is required. Meet
the requirements/specs and pay attention to what is being graded.
You are to post your script in a web accessible directory in your Ruby account.
The files should also be sent to me at burta@unc.edu as a [your Ruby login].zip
file. In the body or message of your email, send me the URL of your posted dictionary
script. Don't send me the location of your imported file.
One more time: ask me the questions, not classmates! This work like most work
is an individual effort. Sharing code for this type of problem is easily verifiable.
Andre S. Burton