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.
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>";
}
?>
Get Answers For Free
Most questions answered within 1 hours.