Frequency analysis is the study of the frequency of letters in a text, i.e., the number of occurrences of each letter. In this homework you will create dynamic web pages to perform frequency analysis to a text document entered by the user. You should create two files: hw2 freq form. html and hw2 freq process.php. The file hw2 freq form. html includes a HTML form with a textarea. It collects a text document entered by the user. After the user submits the form hw2 freq process.php processes the data as follows: l) Display the text document that is entered by the user. 2) Change uppercase letters to lowercase letters using the function s 3) Perform frequency analysis find the number of times each lowercase alphabetic letter Ca to 'z') occurs in the text. Display the frequency analysis result in a HTML table in the alphabetic order, i.e. display a list of 26 alphabetic letters and the number of occurrences of each letter. You should write and call your own function freq letter, not use pre-defined PHP functions except strlen function. The function freq letter accepts a string (text document) and a letter, finds and returns the number of times that letter occurs in the string 4) Display the frequency analysis result in a HTML table in the descending order of the letter frequency, from the highest frequency to the lowest frequency, with associated letters. You can use pre-defined PHP functions in this part. Hints: Use the array combine function to create an associative array by using the alphabet array for keys and frequency array for values. Then use one of the sort functions we learned in class to sort the new array as required.

Respuesta :

Answer:

<?php

$keys = range('a', 'z');

$values = array_fill(0, 26, 0);

$freq = array_combine($keys, $values);

$words = "The day on which the Super Bowl is played, now considered by some as an unofficial national holiday, is called 'Super Bowl Sunday'. It is the second-largest day for U.S food consumption, after Thanksgiving Day. In addition, the Super Bowl has frequently been the most-watched American television broadcast of the year; the seven most-watched broadcasts in the U.S television history are Super Bowls. In 2015, Super Bowl XLIX became the most-watched American television program in history with an average audience of 114.4 million viewers; the fifth time in six years the game had set a record, starting with the 2010 Super Bowl, which itself had taken-over the number-one spot held for 27 years by the final episode of M*A*S*H. The Super Bowl is also among the most-watched sporting events in the world, almost all audiences being North American, and is second to soccer's UEFA Champions League final as the most watched annual sporting event worldwide.";

$len = strlen($words);

for ($i=0; $i<$len; $i++) {

$letter = strtolower($words[$i]);

if (array_key_exists($letter, $freq)) {

$freq[$letter]++;

}

}

print_r($freq)

Explanation:

RELAXING NOICE
Relax