Tuesday, 11 August 2015

How To Count Vowel And Consonant In Php

In This Program, we will Find Vowel and Consonant.
"How to count Vowel and Consonant" This is the important program in PHP. Copy this program and save it as any name but with a .php extension, and run it on your WAMP or XAMP server. If You Need Any Help Comment Below.

PHP script vowels from string count number of vowels in php

PHP script to find number of vowels in a string


<html>
<title> Vowels and Consonants Counter</title>
<style>
body {
  font-size:20px;
  font-family:arial;
  color:blue;
  }
</style>


<?php

error_reporting(0);
$values = $_POST['value'];
if(isset($_POST['check'])) {

  if ($values==" ") {
      echo "<script>";
     echo "alert('It Cannot Be Empty!!! Please enter a sentence.');";
     echo "</script>";
     $values=" ";
     $results=" ";
     }
 if ($values != " ") {
   $total_vowels = 0; $total_consonants=0;

      $vowels = Array('a','e','i','o','u','A','E','I','O','U');
      $vowels = Array('a','e','i','o','u','A','E','I','O','U');
      $consonants = Array('b','c','d','f','g','h','j','k','l','m'
                ,'n','p','q','r','s','t','v','w','x','y','z'
                ,'B','C','D','F','G','H','J','K','L','M'
                ,'N','P','Q','R','S','T','V','W','X','Y','Z');

for ($b=0;$b<strlen($values);$b++)
{
    for ($a = 0;$a<10;$a++)
        if ($values[$b] == $vowels[$a])
        {
            $total_vowels++;
            break;
        }

 for ($a = 0;$a<42;$a++)
        if ($values[$b] == $consonants[$a])
        {
            $total_consonants++;
            break;
        }
 }
   $results .=  "==== REPORT ==== ";
   $results .=  "<br><br>";
   $results .= "The sentence is   :=>   " .$values."<br><br><br>";
   $results .= "Total Consonants  :=>  " .$total_consonants."<br>";
   $results .=  "Total Vowels     :=>  " .$total_vowels."<br>";

   }


    }
 


if(isset($_POST['clear'])) {
  $values=" ";
  $results= " ";

}

?>
<body style='background-color: #FF00DD>
<div style='width:800px;margin:auto'>
  <br> <h1 align="center">Vowels and Consonants Counter</h2>
  <br>
<form action="" method="post">
 Enter a Sentence : <input type="text" name="value"    value="<?php echo $values; ?>" autofocus  size=50/>
 <br><br>
   <input type="submit" name="check" value="Find Vowels and Consonants"
  title="Click here to know the number of Vowels and Consonants in a given sentence."/>
  <input type="submit" name="clear" value="Clear"
  title="Click here to clear text box and values on the screen"/>
</form>
<br>
<?php
echo $results;
 ?>
  </body>
</html>

If You Found This Program Helpful Leave A Comment And Do Share With Your Friends.

You May Also Like:-
Palindrome Number In Php
How To Find Armstrong Number In Php

2 comments:

Post a Comment