Building Web Applications

Yüklə 100 Kb.
ölçüsü100 Kb.


  1. Days in Month: Write a function daysInMonth that takes a month (between 1 and 12) as a parameter and returns the number of days in that month in a non-leap year. For example a call to daysInMonth(6) should return 30, because June has 30 days.



























  2. Vowel Count: Write a function called vowelCount which accepts a string as a parameter, and returns the number of vowels in the in string. Vowels include a, e, i, o, and u. You may assume the string will be all lowercase.

  3. 1337 5p34k: Write a function leetspeak() which accepts a string as a parameter and returns a "leetspeak" version of the string. “Leetspeak” is an internet slang in which various English letters are replaced with other ASCII characters similar in appearance. The following table shows some common leetspeak translations.

















    You should replace at least English five characters with their leetspeak equivalent. For more information about leetspeak, visit

  4. Palindromes: Write a function isPalindrome that accepts a string as a parameter and returns true if the string is a palindrome and false otherwise. A string is considered a palindrome if it has the same sequence of letters when reversed (for example, "radar", "toot", "mom", "a", ""). Your function should be case-insensitive; for example, "Mom" and "RAdar" should be considered palindromes.

  5. Drunken Capitalizer: Write a PHP function called drunkenCapitalizer that accepts a String as a parameter and returns the same String with randomly capitalized characters. For example, drunkenCapitalizer("php rules") could return “PHP RULES”, “pHp rULes”, “Php RULEs” or “PHP rules”.

    Switching cases is not needed; you are only required to randomly capitalize letters. So calling drunkenCapitalizer("PHP RULES") would only return “PHP RULES”.

  6. Fix Spacing: Write a function called fixSpacing which accepts a filename as a parameter. The function should reduce all multiple spaces or tabs to a single space, replacing the old contents of the file. Fox example, an input file could contain the following text:

four score and

seven years ago our

fathers brought forth

on this continent

a new


    After calling fixSpacing, the contents of the file should be as follows:

four score and

seven years ago our

fathers brought forth

on this continent

a new


    Each word is to appear on the same line in new file as it appears in the original file. Notice that lines can be blank.

  1. Search Terms: Write a function searchTerms() that takes a search string as a parameter and returns an array of all search terms in the string. Every token in the string is considered a search term, except for tokens wrapped in double quotation marks: these phrases should be treated as a single search term. You may assume that all tokens in the string are separated by exactly one space and that no search string has an odd number of double quotation marks – that is, all beginning quotation marks have a matching set of ending quotation marks.

    For example, searchTerms("curious george") returns {"curious", "george"} and searchTerms(‘"The Man with the Yellow Hat"’) returns {"The Man with the Yellow Hat"}.

  2. Line sums: Write a PHP function called lineSum that accepts one integer and a filename as a parameter and returns the sum of the integers on that line number. For example, you may have a file named sums.txt that contains the following data:

15 10
20 25
50 60
75 100

    A call to lineSum( "sums.txt", 2) returns 25, and a call to lineSum("sums.txt", 5) returns 200.

  1. GCD and Euclid’s Algorithm: Write a function named gcd that accepts two integers as parameters and returns the greatest common divisor (GCD) of the two numbers. The greatest common divisor of two integers a and b is the largest integer that is a factor of both a and b. The GCD of any number and 1 is 1, and the GCD of any number and 0 is that number.

    One efficient way to compute the GCD is to use Euclid's algorithm, which states the following:

    gcd(a, b) = gcd(b, a % b)

    gcd(a, 0) = Absolute value of a

    For example:

    gcd(24, 84) returns 12,

    gcd(105, 45) returns 15, and

    gcd(0, 8) returns 8.

  2. Inside Out: Write a PHP function called insideOut() that will accept an array and return it with its innermost elements swapped with its outer most elements. For example, calling insideOut(array(1, 2, 2, 1)) would return the array: (2, 1, 1, 2).

    Similarly, the method call insideOut(array("Everyone", "says", "Kelly", "is", "REALLY", "awesome")) would result in: ("Kelly", "says", "Everyone", "awesome", "REALLY", "is").

    The array should only be altered if it has an even number of elements. Return the array passed in if this is not the case.

  3. Emailidate: Create a function called emailidate() that validates email addresses. The function takes as a parameter a string of email addresses delimited by commas. It should return an array of valid email addresses. An email address is considered valid if it is of the form a@b.c, where a, b, and c are non-empty strings. Invalid email addresses are ignored. If none of the email addresses are valid, the function should return FALSE.

  4. University Info: Write a function universityInfo() which accepts a university name as a parameter and returns an array containing information about the given university. The array should have a "location" key, whose value is the university's location, a "founded" key, whose value is the founding date of the university, and a "name" key containing the name of the university. The information about the university is stored in a text file called unidata.txt and has the following format:

University Name
University Location
Date Founded
University Name
University Location
Date Founded

You may assume any university name passed to universityInfo() can be found in the text file and that all universities in the text file have all required information. This function should be case insensitive, i.e. universityInfo("UnIveRsItY OF washington") should return the same results as universityInfo("University of Washington").

Example call:
$info = universityInfo("University of Washington");
echo $info[“name”]; //outputs "University of Washington"
echo $info[“location”]; //outputs "Seattle, Washinton"
echo $info[“founded”]; //outputs "1861"

  1. Folder Crawler: Write a PHP function called folderCrawler() that takes a full path to a folder as a parameter and outputs the HTML for an unordered list of all the files in that folder. The filenames should link to the files themselves, and before every filename you should display an appropriate icon based on the file extension. All icon images are in a folder called icons located in the root directory of the website and each icon is saved as a gif file named “.gif”; for example, the icon for an HTML file is called “html.gif.” You may assume that every file extension has an icon.

  2. Welcome Message: The following webpage has a form prompting the user for his or her name. Edit the HTML and use embedded PHP to modify the following webpage to display a welcome message of the form, “Hello, !” if the user types his or her name into the text box and presses “Enter.” The form should send the submission as a POST request and the welcome message should be displayed in as a level one heading above the form.


Welcome to my page!

Enter your name:

Kataloq: supplements

Yüklə 100 Kb.

Dostları ilə paylaş:

Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur © 2022
rəhbərliyinə müraciət

    Ana səhifə