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...
html/php 1. Create an html page (with an html file ending) that contains a form. This...
html/php 1. Create an html page (with an html file ending) that contains a form. This form will accept a number from the user. The form will then send this number to the assignment3.php program by using either GET or POST. 2. The assignment3.php program will read the value in the textbox and place it into the variable "myvalue". The program will then use either a switch statement or IF/THEN/ELSE statement to determine if the value entered is within 10...
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...
PHP calculator problem Create a calculator class that will add, subtract, multiply, and divide two numbers....
PHP calculator problem Create a calculator class that will add, subtract, multiply, and divide two numbers. It will have a method that will accept three arguments consisting of a string and two numbers example ("+", 4, 5) where the string is the operator and the numbers are what will be used in the calculation. It doesn't need an HTML form, all the arguments are put in through the method. The class must check for a correct operator (+,*,-,/), and a...
Here is the code I am supposed to Analyze: // If we want to use the...
Here is the code I am supposed to Analyze: // If we want to use the Scanner class (type) to get user input, we need // to import the following Java package that includes the Scanner class // definitions. We do not have to add an import statement to use the // print() or println() methods of the System object, because they // are built in. import java.util.Scanner; public class PRG420Week1_AnalyzeAssignment { /* The main() method you see below is...
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...
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...
In the previous assessment, you used a static set of named variables to store the data...
In the previous assessment, you used a static set of named variables to store the data that was entered in a form to be output in a message. For this assessment, you will use the invitation.html file that you modified in the previous assessment to create a more effective process for entering information and creating invitations for volunteers. Rather than having to enter each volunteer and create an invitation one at a time, you will create a script that will...