| CSC 325 | Grinnell College | Fall, 2008 |
| Databases and Web Application Design | ||
This laboratory exercise provides practice with strings and string functions in PHP.
In the earlier lab on dynamic Web pages, we worked with forms and input boxes as a mechanism for getting data into a PHP program. Another type of input is the textarea box. For example, the code
<textarea name="example" cols=50 rows = 12></textarea>
specifies a box that is 50 columns wide and 12 rows tall:
After clicking submit, we can retrieve data entered into this box with the $_GET and $_POST variables, just as for other types of input data.
Chapter 4 of our textbook describes a variety of string functions available within PHP. You may also want to consult the PHP Manual. (Look under "Text Processing" in the "Function Reference Chapter". With this section, consult the "String Functions" link under "Strings".)
Consider the following problem:
Retrieve text from a textarea box, and count the number of times each word appears.
One possible algorithm for solving this problem is:
Step F in the outline specifies that the list of words be sorted. For both approach 1 and approach 2 in Step G, explain any significance of Step F. For example, will the approach work without sorting? Will the sorting be useful, even if it is not essential? How would the result be different if sorting was not done?
Implement both algorithms (i.e., using both approaches 1 and 2 in Step G) in PHP code.
This document is available on the World Wide Web as
http://www.cs.grinnell.edu/~walker/courses/325.fa08/lab-php-strings.shtml
|
created 20 August 2008 last revised 17 September 2008 |
|
| For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |