You are on page 1of 2

Aim:- Write a PHP function to count the total number of vowels (a,e,I,o,u) from the string .

Accept string by using HTML form.

<!doctype html>
<html><head><title>Vowels in string</title></head>
<body>
<h2>Number of vowels in string</h2>
<form method="post">
<input type="text" name="string">
<input type="submit">
</form></body></html>

<?php
if($_POST)
{
$string=strtolower($_POST['string']);
$vowels=array('a','e','i','o','u');
$len=strlen($string);
$num=0;
for($i=0;$i<$len;$i++)
{
if(in_array($string[$i],$vowels))
{
$num++;
}
}
echo"Length of string is".$len;
echo"<br>Number of vowels in string :- ".$num;
}
?>

You might also like