Question

Count the vowels in a string You'll create an array of 5 Strings (words and or...

Count the vowels in a string

You'll create an array of 5 Strings (words and or phrases). Then, you will determine the number of vowels in each string and display each in a meaningful way.

Examples: (Your choice as to how this will look. But, it must be neat and meaningful.)

a nut for a jar of tuna: 8 vowels

OR

8 vowels: a nut for a jar of tuna

Must include this code within <?php and ?> tags

  • Includes a title (using a header tag)
  • Includes a description to the user
  • Produces appropriate feedback as to what the program is to do (Meaningful output)

Uses form for user input to produce the correct results based on what the program is to do:

Clean, easy to read, indentation, etc.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PHP code:

<!Doctype html>
<html>
<head>
<title>Count number of vowels in a given string</title>
</head>
<body>

<!--html form-->
<form action="" method="post">
Please Enter a String:
<input type="text" name="str"/>
<input type="submit" value="Click" />
</form>
<!--end of html form-->

<!--php code starts-->
<?php

//The error_reporting() function specifies which errors are reported.
error_reporting('0');

// if ($_POST) is true
// checking that the HTML form is submited by the method="post" or not.
if($_POST){

// collecting the value of input field using $_POST['parameter']
// storing it in the "str" variable.

$str=$_POST['str'];

// find length of string using strlen() function.
$len=strlen($str);

//initializing a new variable $count to count the no. of vowels.
//initialize default value count=0.

$count=0;
// using for loop iterate every string letter
for($i=0;$i<=$len;$i++)
{
// checking if any vowel is present either in upper or lower case.
       // convert every letter uppercase using build-in strtoupper function.


if(strtoupper($str[$i])=='A' || strtoupper($str[$i])=='E' || strtoupper($str[$i])=='I' ||
   strtoupper($str[$i])=='O' || strtoupper($str[$i])=='U'){


$count++;//increment the count++
   }
}
// display the number of vowels in a given string
echo "<br>$str: $count vowels";
}

?>

<!--php code ends-->

</body>
</html>

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Count the vowels in a string You'll create an array of 5 Strings (words and or...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that uses a recursive function to determine whether a string is a character-unit...

    Write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive comparisons and not ignoring spaces are indicated with flags. For example "A nut for a jar of tuna" is a palindrome if spaces are ignored and not otherwise. "Step on no pets" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive. Background Palindromes are character sequences...

  • Create a C# program in visual studios called FortuneCookie whose Main() method contains an array of...

    Create a C# program in visual studios called FortuneCookie whose Main() method contains an array of at least 8 strings with fortune-telling phrases. The program should randomly select 2 different phrases and pass them to a method that displays them. A random number generator should be used to select the phrases from random positions in the array and the length of the array should be used to determine one of the random number generator range boundaries (i.e., do not hardcode...

  • Hi I how do i use a vector to search a array for a string that...

    Hi I how do i use a vector to search a array for a string that user has enter into the console. here is some of the instructions for the programing I am trying to work on The purpose of this program is to write a class whose job is to read up to 10,000 names into a string array. The class sorts the names and then the user can ask the class to find full names containing a name...

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

  • Note wordBank, an array of 10 strings (char *s). Your program should do the following: 1....

    Note wordBank, an array of 10 strings (char *s). Your program should do the following: 1. Select a word at random from the wordBank. This is done for you. 2. On each turn display the word, with letters not yet guessed showing as *'s, and letters that have been guessed showing in their correct location 3. The user should have 10 attempts (?lives?). Each unsuccessful guess costs one attempt. Successful guesses do NOT count as a turn. 4. You must...

  • Assignment #6 - Arrays and Strings - Making random sentences! Due: Tuesday April 2, 11:59:00 pm...

    Assignment #6 - Arrays and Strings - Making random sentences! Due: Tuesday April 2, 11:59:00 pm Objective This assignment will consist of writing a program that involves practice with arrays, random number generation, and Strings. You may use c-strings or string objects here, however, string objects is recommended. Exercise Filename: sentences.cpp Write a program that uses random-number generation to create sentences. Create four arrays of strings (string objects highly suggested over c-strings) called article, noun, verb, and preposition. The arrays...

  • You will create your own silly story based on information provided by the user. For example,...

    You will create your own silly story based on information provided by the user. For example, the parts in bold were entered by the user. For ideas see: Mad Libs. My Silly Story name: Frank Zhang whole number: 345 body part: stomach noun: cup floating point number: 1.23 clothing article: hat destination: Colorado goal: degree The resulting story is: Congratulations! Today is your 345 day. You're off to Colorado! You're off and away! You have brains in your stomach, You...

  • Use c-strings for the following project: Write a C++ program that declares an array containing up...

    Use c-strings for the following project: Write a C++ program that declares an array containing up to a maximum of 20 sentences, each sentence of maximum 81 characters long, using c-strings. Continue reading sentences from the user and store them in the array of sentences, until the user enters a NULL string for the sentence or 20 sentences have been entered. Then, one by one, display each sentence entered by the user and present the following menu of operations on...

  • Overview: You will be writing classes that implement a playlist simulation for a music streaming app.The...

    Overview: You will be writing classes that implement a playlist simulation for a music streaming app.The Playlist class will contain a dynamic array of Song objects, and the Song class contains several pieces of information about a song. You will need to: 1) Finish the writing of two classes: Song and Playlist. The full header file for the Song class has been provided in a file called Song.h. 2) Write a main program (filename menu.cpp) that creates a single Playlist...

  • Introduction In this final programming exercise, you'll get a chance to put together many of the...

    Introduction In this final programming exercise, you'll get a chance to put together many of the techniques used during this semester while incorporating OOP techniques to develop a simple song playlist class. This playlist class allows a user to add, remove and display songs in a playlist. The Base Class, Derived Class and Test Client Unlike the other PAs you completed in zyLabs, for this PA you will be creating THREE Java files in IntelliJ to submit. You will need...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT