Accept a string from the user and check whether it is a palindrome or not
(Implement stack operations using array built-in functions).
a2seta2.html
<html>
<body>
<form method="get" action="a2seta2.php">
Enter String:
<input type='text' name='str' value=''><br>
<input type='submit' name='submit' value='submit'>
</form>
</body>
</html>
a2seta2.php
<?php
$s=$_GET['str'];
$flag=0;
for($i=0;$i<strlen($s);$i++)
{
array_push($a[$i]=$s[$i]);
}
echo"<br>";
print_r($a);
for($i=0;$i<strlen($s);$i++)
{
$d[$i]=array_pop($a);
}
echo "<br>";
print_r($d);
for($i=0;$i<strlen($s);$i++)
{
if($s[$i]!=$d[$i])
{
$flag=1;
break;
}
}
if($flag==0)
echo "<br>String is Palindrome.";
else
echo "<br>String is not Palindrome.";
?>
0 Comments
If anyone has Doubts or suggestions please let me know