Question

Need this done using PHP code and not javascript Create a PHP form with a textarea...

Need this done using PHP code and not javascript

Create a PHP form with a textarea field input and a submit button. The textarea field should be able to accept up to 250 characters. When the user clicks the Submit button, read the text in the textarea and display the following results on a web age. At the bottom of the page include a link back to the form.

Number of characters:

Number of words: (hint: explode the string into an array based on spaces and get the length of the array)

Generate a random integer between 1 and the number of words , then use that number to get that word from the array of words and display it. So if you generate the number 25, display the number 25 and the 25th word.

Display the string as all capital letters.

Starting at the 10th character, display 10 characters.

Display the string with all instances of the word "and" (or any variation of capitalization) changed to "&"

Search the string and see if it has the strings "REDSTART" and "REDEND" You can search for it as all caps, we will assume it will always be capitalized. Display the string with those removed but anything that was between them is bold and in red. I would create a class called redtext and find a way to replace those REDSTART and REDEND tags with some span tags.  
So this string: We need to REDSTART stop REDEND the violence.
Becomes: We need to stop the violence.

Be sure your page(s) are named correctly (both of them) and they both have the correct header displayed at the top:
Your Name - IT 2320 - Lab 5

Create a form with a textarea field input and a submit button. The textarea field should be able to accept up to 250 characters. When the user clicks the Submit button, read the text in the textarea and display the following results on a web age. At the bottom of the page include a link back to the form.

Number of characters:

Number of words: (hint: explode the string into an array based on spaces and get the length of the array)

Generate a random integer between 1 and the number of words , then use that number to get that word from the array of words and display it. So if you generate the number 25, display the number 25 and the 25th word.

Display the string as all capital letters.

Starting at the 10th character, display 10 characters.

Display the string with all instances of the word "and" (or any variation of capitalization) changed to "&"

Search the string and see if it has the strings "REDSTART" and "REDEND" You can search for it as all caps, we will assume it will always be capitalized. Display the string with those removed but anything that was between them is bold and in red. I would create a class called redtext and find a way to replace those REDSTART and REDEND tags with some span tags.  
So this string: We need to REDSTART stop REDEND the violence.
Becomes: We need to stop the violence.

Homework Answers

Answer #1

index.php

<!DOCTYPE html>
<html>
<head>
        <title>Word count</title>
</head>
<body>
        <form action="text_handling.php" method="POST">
                <textarea cols="30" rows="2" maxlength="250" name="input"></textarea><br>     
                <input type="submit" name="submit">
        </form>
</body>
</html>

text_handling.php

<style type="text/css">
        .redtext{
                color: red;
                font-weight: bold;
        }
</style>
<?php
if($_SERVER["REQUEST_METHOD"]=="POST"){
        $text = $_POST["input"];
        echo "<p><b>The input is: </b>$text</p>";
        echo "<p>Number of characters: ".strlen($text)."</p>";
        $words = explode(" ", $text);
        $word_count = count($words);
        echo "<p>Number of words: ".$word_count."</p>"; //Printing no.of words
        echo "<p>Number of words using str_word_count() function: ".str_word_count($text)."</p>";
        $rand = rand(0,$word_count-1); //array index will start at 0 to word_count-1
        $randword = $words[$rand];//Taking random word
        echo "<p>Random word is::  ".strtoupper($randword)."</p>"; //printing random word
        echo "<p>".substr($text, 9,10)."</p>";//from 10th to 10 characters, starting from 9 because index will start from 10
        
        $strpos_str = stripos($text, "REDSTART");
        $strpos_end = stripos($text, "REDEND");
        $strend = substr($text,$strpos_str+8,$strpos_end-($strpos_str+8)); //find the text between two words.
        $strend = trim($strend);
        // First substring is to print the string upto redstart and then skipping it.
        // Next span is to print the text in between the redstart and redend.
        //Next substring is to print the text after the redend.
        echo "<p>".substr($text,0,$strpos_str)."<span class='redtext'>$strend</span>".substr($text, $strpos_end+6)."</p>";
        //Link for the go back
        echo "<a href='word_count.php'>Go Back << </a>";

}
?>

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please linked both files. For this assignment you need to create a ToDo list using Javascript,...
Please linked both files. For this assignment you need to create a ToDo list using Javascript, along with HTML and CSS. Begin by creating a HTML page called todo.html. Then create a Javascript file called todo.js and link it in to the HTML page using a script tag. All Javascript for the assignment must be in the separate file. (For CSS, feel free to include styles in a style block at the top of the HTML page, or to link...
<?php    if(isset($_GET['submit'])){ //sanitize the input        /* Check the error from the input: if...
<?php    if(isset($_GET['submit'])){ //sanitize the input        /* Check the error from the input: if input from user is empty -> get an error string variable if input is not empty -> use preg_match() to match the pattern $pattern = "/^[1-9][0-9]{2}(\.|\-)[0-9]{3}(\.|\-)[0-9]{4}$/"; -> if it's a matched, get a success string variable */           } ?> <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link...
For this assignment, create an html page that has a login form. The form should have...
For this assignment, create an html page that has a login form. The form should have 3 input elements -- 1. This should have a type text for the user to enter UserName 2. This should have a type password (like text except cannot see the text that is typed in), for the user to enter password. 3. Submit button (type submit, as we did in class on 2/6). The form method should be set to POST and the action...
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes...
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes a ransom note. It is not wrriten by hand to avoid having his hand writing being recognized, so the kid napper uses a magazine to create a ransom note. We need to find out, given the ransom note string and magazine string, is it possible to given ransom note. The kidnapper can use individual characters of words. Here is how your program should work...
Using Python, write the following code. You are to allow the user to enter the daily...
Using Python, write the following code. You are to allow the user to enter the daily temperature as a floating-point number. You should make the assumption that you are recording temperatures in Fahrenheit. You should allow the user to continue entering temperatures until the value -999 is entered. This number should not be considered a temperature, but just a flag to stop the program. As the user enters a temperature, you should display the following each time: Current Temperature: 999...
This assignment involves using a binary search tree (BST) to keep track of all words in...
This assignment involves using a binary search tree (BST) to keep track of all words in a text document. It produces a cross-reference, or a concordance. This is very much like assignment 4, except that you must use a different data structure. You may use some of the code you wrote for that assignment, such as input parsing, for this one. Remember that in a binary search tree, the value to the left of the root is less than the...
**please write code with function definition taking in input and use given variable names** for e.g....
**please write code with function definition taking in input and use given variable names** for e.g. List matchNames(List inputNames, List secRecords) Java or Python Please Note:    * The function is expected to return a STRING_ARRAY.      * The function accepts following parameters:      *  1. STRING_ARRAY inputNames      *  2. STRING_ARRAY secRecords      */ Problem Statement Introduction Imagine you are helping the Security Exchange Commission (SEC) respond to anonymous tips. One of the biggest problems the team faces is handling the transcription of the companies reported...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT