Question: Write the PHP code for a web page that searches for names that contain a given letter a given number of times, case-insensitively. Your web

Write the PHP code for a web page that searches for names that contain a given

letter a given number of times, case-insensitively. Your web service would be

located in a file named q4.php on the server. In this same directory is a file peeps.txt;

each line of this file contains a name. For example:

Helene Martin Robert Purple Marty Stepp Stuart Reges Bob Loblaw

The names are guaranteed to be non-empty and unique.

Your web service accepts a query parameter named letter indicating the character to be searched for, and a parameter named times indicating how many times that character must occur, case-insensitively. For each name that contains the letter at least the given number of times, an HTML paragraph should be printed indicating

this with the name in bold along with the number of times it contains the letter. For

example, if the following query is given, this output is produced:

q4.php?letter=R×=2

Robert Purple contains R exactly 3 times.

Stuart Reges contains R exactly 2 times.

If no names contain the given character the given number of times, output a

message saying so:

q4.php?letter=x×=1

No name contained x enough times.

If one or both of the required query parameters is not passed, your service must produce an error message instructing the user about how to fix it. You should also generate an error message if the letter parameter is not a one-letter string or if the times parameter is not a positive number. (Any times value ? 0 is invalid and anything else is valid.)

q4.php?letter=thingy×=-4

q4.php?letter=t

q4.php?times=7

q4.php

The above are Invalid Request

Your code should not output a complete HTML page. Output a partial page

containing only the paragraphs indicated.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!