Write a PHP script for the following: Design a form to accept a string. Write a 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. Check whether the given string is a palindrome or not, without using built-in function. (Use radio buttons and the concept of function. Use ‘include’ construct or require stmt.)
<html>
<body>
<form
action="slip1-1.php" method=POST>
<pre>
Enter
string : <input type="text" name=str>
<input
type="radio" name=ch1 value="1"> Vowel Count
<input
type="radio" name=ch1 value="2"> Palindrome
<input
type="submit" value="submit" >
</pre>
</form>
</body>
</html>
slip1-1.php
<?php
include("slip1.php");
$ch=$_POST['ch1'];
$str1=$_POST['str'];
switch($ch)
{
case"1":tvowel($str1);
break;
case"2":checkpalindrome($str1);
break;
default:echo
"invalid choice";
}
?>
slip1.php
<?php
function tvowel($str1)
{
$ca=0;$ce=0;$ci=0;$co=0;$cu=0;
$len=strlen($str1);
for($i=0; $i<$len;
$i++)
{
switch($str1[$i])
{
case'a':
case'A':echo"\n
<br> $str1[$i] found at position $i";
$ca++;
break;
case'e':
case'E':echo"\n
<br> $str1[$i] found at position $i";
$ce++;
break;
case'i':
case'I':echo"\n
<br> $str1[$i] found at position $i";
$ci++;
break;
case'o':
case'O':echo"\n
<br> $str1[$i] found at position $i";
$co++;
break;
case'u':
case'U':echo"\n
<br> $str1[$i] found at position $i";
$cu++;
break;
}
}
echo "
<br>Occurence of 'a' : ".$ca;
echo "<br>Occurence
of 'e' : ".$ce;
echo
"<br>Occurence of 'i' : ".$ci;
echo
"<br>Occurence of 'o' : ".$co;
echo
"<br>Occurence of 'u' : ".$cu;
}
function
checkpalindrome($str1)
{
$len=strlen($str1);
for($i=0,$j=$len-1;$i<$len/2&&$j>=0;$i++,$j--)
{
if($str1[$i]!=$str1[$j])
{
echo"$str1 is not
pailindrome";
return;
}
}
echo "$str1 is
pailindrome";
}
?>