Web Technologies

Web Technologies 

Slip20

Q.1)  Design a HTML form to accept a String. Write a PHP function to count the total number of vowels (a,e,i,o,u) from the string. Show the occurrences of each vowel from the string [Marks30] 

Solution

a1.html
<form method='post' action='palin_vowel'>
Enter String :
<input type='text' name='s'><br>
Select Option :<br>
<input type='radio' name='op' value='vowel'>
Vowels<br>
<input type='submit'>
<input type='reset'>
</form>

palin_vowel.php
<?php
function is_vowel($c)
{
return $c=='a' || $c=='e' || $c=='i' || $c=='o' || $c=='u';
}

function count_vowels($s)
{
$n=strlen($s);
$tot=0;
$counts=array('a'=>0,'e'=>0,'i'=>0,'o'=>0,'u'=>0);
for($i=0;$i<$n;$i++)
{
$c=$s[$i];
if(is_vowel($c))
{
$tot++;
$counts[$c]++;
echo "$i : $c"." <br>";
}
}

print_r($counts);
echo '<br>';
return $tot;
}

$s=$_POST['s'];
$op=$_POST['op'];

switch($op)
{
case 'vowel': printf("vowel count=%d",count_vowels($s));
      break;
}
?>

BCA Pratical Solution

My name is Vivek And I from Mumbai and Complete my Graduation Bca.my Age is 23 Years.

Post a Comment

Previous Post Next Post