CS 1520 / COE 1520: Programming Languages for Web Applications (Fall 2005)
Department of Computer Science, University of Pittsburgh
Assignment 3: PHP: Online Mad Libs
(Due 11:59pm, Monday, November 21st)
Goal
You will use PHP to create an online game similar to
Mad Libs, a popular word game for young children.
Introduction
In a Mad Lib, the player is given a list of blanks to fill in, with
labels such as "noun," "verb, "name", "something round", etc. Once all
of the blanks are filled in, the player turns the page and substitutes
these words into the corresponding blanks of a story. The end result
is usually a very funny story because the player had no idea what the
context would be for the words he/she filled in.
Specifications
You will create three pages in PHP that allow a user to select a
story, choose words to be substituted into that story, and view the
finished story. You will also provide buttons for the user to return
to a previous page if he/she wants to change something.
(i) Story files
Your program must be able to read in a "story file," which contains a
mix of story text and special tags that identify what should be
substituted into the story. An example story file would be:
One day, I was walking through the <# adjective #> part of
Pittsburgh when I ran into a huge stack of <# plural noun #>!
It was the most <# adjective #> sight I had ever seen. I tried
to call my best friend, <# proper noun #>, to tell <# him/her #>
about it but all of the phone circuits were busy.
As demonstrated by the above story, your program must be able to
identify tags of the form "<# label #>". These tags can be of two
types:
- Multiple choice: Any tag containing a forward slash (ex: <#
him/her #> or <# he/she/it #>) is a multiple choice tag
- Free response: Any tag not containing a forward slash (ex:
<# proper noun #>) is a free response tag
(ii) Required pages
Your program must consist of three pages: story selection, word
selection, and story display.
- (a) Story selection
-
-
This is the first page of your program. On this page, the user
will be presented with a pulldown menu listing all of the
stories available to be used in the game. The user will select
a story from this list and hit a submit button, which will
take the user to the word selection page.
Your program will give the user a choice between three story files:
story1.txt, story2.txt, story3.txt.
- (b) Word selection
-
-
Using the story selected in the previous page, your program
must read through the story file and extract all word tags
from it.
- For every multiple choice tag in the story file, your word
selection page must allow the user to select among the
multiple choices using radio buttons.
- For every free response tag in the story file, your word
selection page must show the type of word to be chosen
(e.g. "adjective") and a text field where the user can
input a word or phrase.
At the bottom of your word selection page there should be a "Submit"
button and a "Go back" button. "Submit" will move the user to the
"story display" page, while "Go back" will return the user to the
first page to select a new story.
A word selection page using our example story might look
like this.
Note: If the user attempts to access the word selection page
directly, without first selecting a story from the story selection
page, your program should print an error message and provide a link
for the user to go select a story first.
- (c) Story display
-
-
On this page, you must show the user the story he/she
created. Your program should use HTML to print the story, and
all word tags in the story must be replaced by the words that
were chosen on the word selection page. These words should be
in bold text so they can be easily noticed. For example, the
story from earlier might be displayed as:
One day, I was walking through the laziest part of Pittsburgh
when I ran into a huge stack of pigs! It was the most colorful
sight I had ever seen. I tried to call my best friend, Nebraska,
to tell her about it but all of the phone circuits were busy.
In addition, you must also show the user his/her word selections at
the top of the page. Each word should be labeled with a number
(starting with 1) and should show the user both the word type
(e.g. "adjective") and the word chosen (e.g. "laziest"). For multiple
choice selections, display all available choices (e.g. "him/her") as
well as the choice selected (e.g. "her"). For example, using the story
above, the top of your page should show:
1) adjective: laziest
2) plural noun: pigs
3) adjective: colorful
4) proper noun: Nebraska
5) him/her: her
Finally, your story display page must include a "Go back" button that
will return the user to the word selection page, where he/she may
select new words to put into the story. When using the "Go back"
button in this case, the word selection form should be filled with all
the previously filled-in options.
A story display page using our example story might look
like this.
Note: If the user attempts to access the story display page
directly, without first selecting a story from the story selection
page or selecting words from the word selection page, your program
should print an error message and provide a link for the user to go
select a story first.
Submitting your assignment
- This project is to be done independently.
- To submit your assignment:
- combine all the submitted files into a single file (using zip or tar)
e.g., the following creates a zip file (called madlibs.zip) out
of combining three php files: madlib1.php, madlib2.php, madlib3.php:
zip madlibs.zip madlib1.php madlib2.php madlib3.php
- name this file using your userID
e.g., name your file user01.zip if your account is user01
and you used zip:
cp madlibs.zip user01.zip
- copy the answer file into the directory:
/afs/cs.pitt.edu/public/incoming/CS1520/3/
e.g.,
cp user01.zip /afs/cs.pitt.edu/public/incoming/CS1520/3/
- You must submit your assignment before the due date (
11:59pm, Monday, November 21st) to avoid getting any late penalty.
The timestamp of the electronic submission will determine if you have
met the deadline. There will be no late submissions allowed
after 11:59pm, November 23rd
Notes on the submission process
- You can copy your file only once in the incoming
directory and you cannot edit or remove your submission.
So, copy only your final submission.
- You should list the contents of the incoming directory (e.g.,
using the
ls -l command in Unix) to make sure that your
submission is there and it has a non-zero file size.
- If you find that there is a problem with your submission and
must resubmit it, please use an alternate filename extension
to do so, (e.g,
user01.second.cgi) and email the
instructor.
- It is recommended to first upload your project to your Pitt
account (e.g., using ftp) and then copy the file from your
account to the specified incoming directory.
- It is your responsibility to submit a file that is working
properly!.
Back to the class web page