Palindrome Number

A palindrome number is a number which remains same when its digits are reversed.
For example, number 24142 is a palindrome number. On reversing it we?ll get the same number.

Logic:


Palindrome Number in PHP

Example:


<?php
function palindrome($n){  
    $number = $n;  
    $sum = 0;  
    while(floor($number)) {  
    $rem = $number % 10;  
    $sum = $sum * 10 + $rem;  
    $number = $number/10;  
    }  
    return $sum;  
    }  
    $input = 1235321;  
    $num = palindrome($input);  
    if($input==$num){  
    echo "$input is a Palindrome number";  
    } else {  
    echo "$input is not a Palindrome";  
    }  
    
?>
    

On entering the number 23432, we get the following output.

Output

Palindrome Number using Form in PHP

We'll show the logic to check whether a number is palindrome or not.

Example:


                    

<form method="post">        
Enter a Number: <input type="text" name="num"/><br>  
<button type="submit">Check</button>  
</form>  
<?php   
    if($_POST)  
    {  
        //get the value from form  
        $num = $_POST['num'];  
        //reversing the number  
        $reverse = strrev($num);  
          
        //checking if the number and reverse is equal  
        if($num == $reverse){  
            echo "The number $num is Palindrome";     
        }else{  
            echo "The number $num is not a Palindrome";   
        }  
    }  
?>

 
    

On entering the number 23432, we get the following output.

Output

On entering the number 12345, we get the following output.

Output