Friday, June 11, 2021

Count Vowels in PHP

 A simple program to count the vowels, occurrence of vowels in a given string in PHP programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website, kindly contact me also at my email address also. Thank you.

My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.







Program Listings

index.php

<html>

  <head> 

   <title> Count Vowels in PHP </title>

  </head>

  <body> 

      <style type="text/css">

      

      body {

        font-family: arial;

            size: 12px;

      };


        </style>

    <?php


     error_reporting(0);



     $val_str = strtolower($_POST['val_str']);

     

      

   if(isset($_POST['submit'])) {

      

      $results = "<h4>The Number of Vowels : &nbsp;" 

        .count_Vowels($val_str)."</h4>";

      

      $display_strings =  "<h4>The List of Vowels : " 

        .strip_Consonants($val_str)."</h4>";


      $display_vowels = "<h4>Number of Letter A : " 

                         .count_a($val_str)."</h4>";

      $display_vowels .= "<h4>Number of Letter E : " 

                       .count_e($val_str)."</h4>";

      $display_vowels .= "<h4>Number of Letter I : " 

                         .count_i($val_str)."</h4>";

      $display_vowels .= "<h4>Number of Letter O : " 

                       .count_o($val_str)."</h4>";

      $display_vowels .= "<h4>Number of Letter U : " 

                       .count_u($val_str)."</h4>";

      

      }




 if(isset($_POST['clear'])) {

      $val_str = "";

      $results = "";

      $display_strings = "";

    }



function count_Vowels($string)

{

    preg_match_all('/[aeiou]/i', $string, $matches);

    return count($matches[0]);

}

 

function strip_Consonants($string)

{


  $trans = array("b" => "","c"=>"","d"=>"","f"=>"","g"=>"",

                 "h" => "","j"=>"","k"=>"","l"=>"","m"=>"",

                 "n" => "","p"=>"","q"=>"","r"=>"","s"=>"",

                 "t" => "","v"=>"","x"=>"","z"=>"");

  

  return  strtoupper(strtr($string, $trans));

}


function count_a($string)

{


  preg_match_all('/[a]/i', $string, $matches);

  return count($matches[0]);

}


function count_e($string)

{


  preg_match_all('/[e]/i', $string, $matches);

  return count($matches[0]);

}


function count_i($string)

{


  preg_match_all('/[i]/i', $string, $matches);

  return count($matches[0]);

}


function count_o($string)

{


  preg_match_all('/[o]/i', $string, $matches);

  return count($matches[0]);

}


function count_u($string)

{


  preg_match_all('/[u]/i', $string, $matches);

  return count($matches[0]);

}



?>


  <h2> Count Vowels in PHP </h2>

  <p> Mr. Jake Rodriguez Pomperada,MAED-IT, MIT </p>

<form method="post">

   <p>Give a String <input 

    type="text" name="val_str" size=50

     value="<?php echo $val_str; ?>" autofocus required /></p>

      

<input type="submit" name="submit" 

   title="Click here to count the vowels."

   value="Submit" />

   

    &nbsp;&nbsp;&nbsp;

    <input type="submit" name="clear" 

    title="Click here to clear the textbox."

    value="Clear" />

</form>


<?php

   echo $results;

   echo $display_strings;

   echo $display_vowels;

?>

</body>

</html>



No comments:

Post a Comment