Space for google add

Count the total number of vowels (a,e,i,o,u),check whether given string is palindrome or not in PHP.


 

 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.)


 a1seta1.html 

<html>

<body>

<form method="post" action="a1seta1.php">

Enter String :

<input type='text' name='str' value=""><br>

<input type='radio' name='op' value='1'>Total number of count of vowels. <br>

<input type='radio' name='op' value='2'>Total number of occurence of each vovwel.<br>

<input type='radio' name='op' value='3'>String Palindrom.<br>

<input type='submit' name='submit' value='submit'>

</form>

</body>

</html>


vowels.php

<?php

function count1($a)

{

$cnt=0;

for($i=0;$i<strlen($a);$i++)

{

$found=preg_match('/[aeiouAEIOU]/',$a[$i]);

if($found)

{

++$cnt;

}

}

echo "Total count of vowels $cnt.";

}

function palindrome($a)

{

if(IS_NULL($a)==TRUE)

{

echo  "String is NULL";

}

else

{

$n=strlen($a);

$b=$a;

for ( $i = $n - 1,$j=0; $i >=0,$j<$n;$i--,$j++ )

{

  $b[$j]=$a[$i];

}

echo "Original String a= $a<br>";

echo "Reverse String b= $b<br>";

if($a==$b)

echo "Palindrome<br>";

else

echo "No Palindromes";

}

}


function occurence($a)

{

$ca=$ce=$ci=$co=$cu=0;

for($i=0;$i<strlen($a);$i++)

{

if($a[$i]=='a' || $a[$i]=='A')

++$ca;

if($a[$i]=='e' || $a[$i]=='E')

++$ce;

if($a[$i]=='i' || $a[$i]=='I')

++$ci;

if($a[$i]=='o' || $a[$i]=='O')

++$co;

if($a[$i]=='u' || $a[$i]=='U')

++$cu;

}

echo "Occurence of a is $ca<br>";

echo "Occurence of e is $ce<br>";

echo "Occurence of i is $ci<br>";

echo "Occurence of o is $co<br>";

echo "Occurence of u is $cu<br>";

}

?>



a1seta1.php

<?php

include 'vowels.php';

$a=$_POST['str'];

$ch=$_POST['op'];

switch($ch)

{

case 1:

count1($a);

break;

case 2:

occurence($a);

break;

case 3:

palindrome($a);

break;

}

?>

 

Post a Comment

0 Comments