Write a program to print Reverse of any number

<?php
if(isset($_POST['reverse']))
{
$rev=0;
$num=$_POST['rev'];
while($num>=1)
{
$re=$num%10;
$rev=$rev*10+$re;
$num=$num/10;
}
}
?>
<html>
<head>
<title>Reverse</title>
</head>
<body>
<table>
<form method="post">
<tr><td>Number</td><td><input type="text" name="rev"></td></tr>
<tr><td>Reverse is:</td><td><input type="text" value="<?php if(isset($_POST['reverse'])){echo $rev;} ?>" name="rev1"></td></tr>
<tr><td> </td><td><input type="Submit" value="Reverse" name="reverse"></td></tr>
</form>
</table>
</body>
</html>