61. PHP Program to find the given number is Palindrome or Not.
How does this program work?
- In this program you are going to learn about to check if a number is Palindrome number or not using PHP.
- A palindrome number is a number which means if it remains same even after reversing the digits.
- A number said to be a palindrome if original number is equal to the reverse number other wise it is not a palindrome.
Here is the code
<html>
<head>
<title>PHP Program To Check a given number is Palindrome or Not</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num" value="" placeholder="Enter a number"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$n = $_POST['num'];
$x = $n;
$r = 0;
$n1 = 0;
while($n>1)
{
$r = $n % 10;
$n1 = $n1 * 10 + $r;
$n = $n/10;
}
// If orignalInteger and reversedInteger are equal then print palindrome
// Else to print not a palindrome number
if($x == $n1)
{
echo " $x is a Palindrome.";
}
else
{
echo " $x is not a Palindrome.";
}
return 0;
}
?>
</body>
</html>