65. PHP Program to find the Reverse of a given number.
How does this program work?
- This program is used to find the Reverse of a given number using PHP.
- The integer entered by the user is stored in variable n.
- Declare variable r to store reverse number and initialize it with 0.
- Multiply the reverse number by 10, add the remainder which comes after dividing the number by 10.
Here is the code
<html>
<head>
<title>PHP Program To find the Reverse of a given number</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;
while($n>1)
{
$r = $r*10;
$r = $r+($n%10);
$n = $n/10;
}
echo "Reverse of number ". $x . " is: " .$r;
return 0;
}
?>
</body>
</html>