Php to identify whether a number is palindrome or not using floor function.

 

First prepare a form page for inputting purpose

(pali.html)

<!DOCTYPE html>
<html>
<form method="POST" action="palin.php">
Enter Number:<input type="number" name="n1">
<input type="submit">
</form>
</html>






embed php file into form

(palin.php)

<?php
$num=$_POST["n1"];
  function isPalindrome($num) {
    $og = $num;
    $rev = 0;
    while($num > 0) {
      $rem = $num % 10;
      $rev = $rev * 10 + $rem;
      $num = floor($num/10);
    }
    return $og == $rev;
  }
  
  if(isPalindrome($num)) {
    echo "$num is a palindrome number.";
  } else {
    echo "$num is not a palindrome number.";
  }
?>





Comments