Write 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 occurences of each vowel from the string. Check whether the given string is palindrome or not without using built in functions. Use Radio buttons and concept of function


Create A Form Which Contains A selection as well as textbox for String

(complex.html)

<html>
<form method="POST" action="complex.php">
Enter String:<input type="text" name="n1"><br>
<h1> Select Options</h1>
<input type="radio" name="n2" value="count">Vowels<br>
<input type="radio" name="n2" value="occr">Occurences of Vowels<br>
<input type="radio" name="n2" value="palin">Palindrome<br>
<input type="submit" value="submit">
</form>
</html>

Now Embed The Following Php Code into form Tag

(complex.php)


<?php
$str=$_POST["n1"];
$r=$_POST["n2"];
$l=strlen($str);

if($r=="count") {
  function count_var($a,$l) {
    $v=0;
     for($i=0;$i<$l;$i++) {
     if ($a[$i]=='a'|| $a[$i]=='e' ||$a[$i]=='i'||$a[$i]=='o'||$a[$i]=='u'||$a[$i]=='A'||$a[$i]=='E'||$a[$i]=='I'||$a[$i]=='O'||$a[$i]=='U')
     $v++;
    }
   echo "Total Vowels $v";
  } 
  count_var($str,$l);
}
else if($r=="occr") {
 function occur($a,$l) {
 $av=$ev=$iv=$ov=$uv=$cnt=0;
for($i=0;$i<$l;$i++) {
if($a[$i]=='a' || $a[$i]=='A')
$av++;
else if($a[$i]=='e' || $a[$i]=='E')
$ev++;
else if($a[$i]=='i' || $a[$i]=='I')
$iv++;
else if($a[$i]=='o' || $a[$i]=='O')
$ov++;
else if($a[$i]=='u' || $a[$i]=='U')
$uv++;
else $cnt++;
}
echo "Total a/A:$av","<br>";
echo "Total e/E:$ev","<br>";
echo "Total i/I:$iv","<br>";
echo "Total o/O:$ov","<br>";
echo "Total u/U:$uv","<br>";
echo "Total Consonants:$cnt";
}
occur($str,$l);
}
else if($r=="palin") {

  function isPalindrome($str) {
  $str2=strrev($str);
  return $str2==$str;
}
if(isPalindrome($str)) {
echo "Its Palindrome";
}
else {
echo "Not Palindrome";
}
}
?>

Output 1


Output 2(when selecting opt 2)


Output 3(when selecting opt 3)

End







Comments