Question
Write the PHP code for a partial 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 partial 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 names.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, is
given, this output is produced:
names.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:
names.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 HTTP 400 Invalid Request error. You should also generate an HTTP 400 error 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.)
names.php?letter=thingy×=-4
names.php?letter=t
names.php?times=7
names.php
HTTP/1.1 400 Invalid Request
Your code should not output a complete HTML page. Output a partial page containing only the paragraphs indicated. Do not use any print or echo statements in your code.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started