User Tools

Site Tools


eg-259:homework:18

PHP for Web Applications

Adapted from: Robert W. Sebasta, Programming the World-Wide Web, 3rd Edition, Addison Wesley, 2006. Supporting: Contact Hour 22.

Write, test, and debug (if necessary) PHP scripts for the following specifications. For Exercise 1.1, write a function and the code to test it.

1. Homework Exercise from the Lecture

  1. Parameter: A file variable of a file of text, where the words are separated by spaces or colons. Return value: The word that appears most often in the file.

2. Additional Homework Exercises

These additional exercises, all from Chapter 12 of Sebasta, can be tried if you need more challenges.

  1. Write an HTML document to that includes an anchor tag that calls a PHP document. Also write the called PHP document, which returns a randomly chosen greeting from a list of five different greetings. The greeting must be stored as constant strings in the script.
  2. Write the HTML code to create a form with the following capabilities:
    1. A text widget to collect the user's name
    2. Four checkboxes, one each for the following items:
      • Four 100-watt light bulbs for £2.39
      • Eight 100-watt light bulbs for £4.29
      • Four 100-watt long-life light bulbs for £3.95
      • Eight 100-watt long-life light bulbs far £7.49
    3. A collection of three radio buttons that are labeled as follows:
      • Visa
      • MasterCard
      • Delta
  3. Write a PHP script that computes the total cost of the ordered light bulbs from Exercise 2.2 after adding 17.5 percent VAT. The program must inform the user of exactly what was ordered, in a table.
  4. Write the HTML code to provide a form that collects names and telephone numbers. The phone numbers must be in the format ddd-ddd-dddd. Write a PHP script that checks the submitted telephone number to be sure that it conforms to the required format and then returns a response that indicates whether the number was correct.
  5. Modify the PHP script for Exercise 2.1 to count the number of visitors and display that number for each visitor. Hint: Use a file to store the current count.

<note> For exercise 2.1: a random number between 0 and 4 can he computed with these lines:

  # Set the seed for mtrand with the number of microseconds
  # since the last full second of the clock
  mt_srand((double)microtime() * 1000000);
  $number = mtrand(0, 4); # Computes a random integer 0--4

</note>


More Homework Exercises

eg-259/homework/18.txt · Last modified: 2012/03/22 08:25 by eechris