Question

In: Computer Science

Write a PHP script to display in frequency all the words in the submitted paragraph. Convert...

Write a PHP script to display in frequency all the words in the submitted paragraph.
Convert the string to an array of words.
Count the number of times the words are used. Hint: array_count_values($arrayname)
Sort the array in frequency order.
Print the array to the screen. Hint: print_r($arrayname)

Solutions

Expert Solution

If you have any doubts, please give me comment...

<?php

    if(isset($_POST['sentence'])){

        $sentence = $_POST['sentence'];

        //converting the string to an array of words

        $words = explode(" ", $sentence);

        // Count the number of times the words are used

        $frequency = array_count_values($words);

        // Sort the array in frequency order.

        asort($frequency);

        print_r($frequency);

    }

    else{

?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">

<p>

<div><b>Enter your sentence: </b></div>

<textarea name="sentence" row="5" cols="50"></textarea>

</p>

<button type="submit">Submit</button>

</form>

<?php

    }

?>


Related Solutions

Write a PHP Program to display all the $_SERVER elements
Write a PHP Program to display all the $_SERVER elements
Write a simple PHP script. In your script use all of the following: HTML, Javascript, and...
Write a simple PHP script. In your script use all of the following: HTML, Javascript, and PHP.
<?php # Script 10.5 - #5 // This script retrieves all the records from the users...
<?php # Script 10.5 - #5 // This script retrieves all the records from the users table. // This new version allows the results to be sorted in different ways. $page_title = 'View the Current Users'; line 6 include('includes/header.html'); echo '<h1>Registered Users</h1>'; require('mysqli_connect.php'); // Number of records to show per page: $display = 10; // Determine how many pages there are... if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined.    $pages = $_GET['p']; } else { // Need to...
Write a PHP script that checks a word or a phrase (stored in a string variable)...
Write a PHP script that checks a word or a phrase (stored in a string variable) to determine if it is a standard palindrome, a perfect palindrome, or not a palindrome at all. Also, for each letter that the word/phrase contains, count and print the number of times that each consonant and vowel is encountered. Your output will look as follows: Word/phrase: racecar Perfect palindrome Contains consonants: r - 2 c - 2 Contains vowels: a - 2 e -...
Display the shortest words in a sentence in JAVA Write a method that displays all the...
Display the shortest words in a sentence in JAVA Write a method that displays all the shortest words in a given sentence. You are not allowed to use array In the main method, ask the user to enter a sentence and call the method above to display all the shortest words in a given sentence. You must design the algorithms for both the programmer-defined method and the main method.
PHP Question: Write the PHP code to list out all of the dates of the current...
PHP Question: Write the PHP code to list out all of the dates of the current month and assign them to their given days. As an example, for the month of October 2020, the output should look something like this: October 2020       Monday: 5, 12, 19, 26 Tuesday: 6, 13, 20, 27 Wednesday: 7, 14, 21, 28 Thursday: 1, 8, 15, 22, 29 Friday: 2, 9, 16, 23, 30 Saturday: 3, 10, 17, 24, 31 Sunday: 4, 11, 18,...
Write a PHP script that: 1) Has an associative array with 10 student names and test...
Write a PHP script that: 1) Has an associative array with 10 student names and test scores (0 to 100). ie. $test_scores('John' => 95, ... ); 2)Write a function to find the Average of an array. Input is an array, output is the average. Test to make sure an array is inputted. Use ARRAY_SUM and COUNT. 3)Output the test scores highest to lowest, print scores above the average in Green. Find a PHP Sort function for associative arrays, high to...
Write a script to display the following patterns on the screen. Number of rows and columns...
Write a script to display the following patterns on the screen. Number of rows and columns are taken from the command arguments; if they are missing, set default to 3 (rows) and 4 (columns). Hint: you will use a nested loop. **** **** **** a) Display the source code in an editor (#4-11) b) Execute your script in the terminal, and display the command and the result (#4-12)
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell script to take a directory as an argument and display the contents of that directory (10pts) Write a shell script that takes any command as a parameter and displays help on that command (e.g. the result of the execution of man <command>). (10pts) Write a shell script that requires two file names as parameters and copies content of one file into another without asking...
Bash Script Write a script using while-do-done loop to convert the kilometers to miles. - Ask...
Bash Script Write a script using while-do-done loop to convert the kilometers to miles. - Ask the user to input the number of kilometers they need to travel. - Display the number of equivalent miles for the number. Use formula, Kilometers = miles/0.62137 - Every time the loop runs, it should ask the user if they want to continue, if user enters “Y” or “y”, then the loop runs again, if user enters “N” or “n”, then stop the loop...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT