Q. Accept a string from the user and check whether it is a palindrome or not
(Implement stack operations using array built-in functions).
HTML File:
<html>
<h3 > PALLINDROM </h3>
<form action='ass1a2.php' method='post'>
Enter a string::<input type='text' name=str><br><br>
<input type='submit' name='OK'> <input type='reset' name='CLEAR'>
</form>
</body>
</html>
PHP Function:
NOTE: PHP function is saved as "ass1a2.php"
<?php
$s=$_POST['str'];
$stack=array();
for($i=0;$i<strlen($s);$i++)
array_push($stack,$s[$i]);
for($i=0;$i<strlen($s);$i++)
if(array_pop($stack)!=$s[$i])
break;
if($i==strlen($s))
echo "$s is pallindrome:";
else
echo "$s is not pallindrom:";
?>
Output:
HTML File:
<html>
<h3 > PALLINDROM </h3>
<form action='ass1a2.php' method='post'>
Enter a string::<input type='text' name=str><br><br>
<input type='submit' name='OK'> <input type='reset' name='CLEAR'>
</form>
</body>
</html>
PHP Function:
NOTE: PHP function is saved as "ass1a2.php"
<?php
$s=$_POST['str'];
$stack=array();
for($i=0;$i<strlen($s);$i++)
array_push($stack,$s[$i]);
for($i=0;$i<strlen($s);$i++)
if(array_pop($stack)!=$s[$i])
break;
if($i==strlen($s))
echo "$s is pallindrome:";
else
echo "$s is not pallindrom:";
?>
Output:
0 Comments