Palindrome Program in PHP

Palindrome Program in PHP

<?php
	   $original = 1001; 
	   $number=$original;
    $temp = $number;   
    $new = 0;   
    while (floor($temp)) {   
        $d = $temp % 10;   
        $new = $new * 10 + $d;   
        $temp = $temp/10;   
    }   
    if ($new == $number){   
         echo "Palindrome". $original;
		}
		else{ 
        echo "Not a Palindrome".$original; 
    }            
?>

Output

Palindrome1001

Palindrome Program in PHP with form values entered by the user

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</hea  d>
<body>

<form  method="POST"> 

Enter Number: <input type="text" name="1"><br>


<input type="submit"value="Check Number" name="submit">

</form>





<?php
if (isset($_POST['submit'])){
$units=$_POST['1'];
	   $original = 1001; 
	   $number=$original;
    $temp = $number;   
    $new = 0;   
    while (floor($temp)) {   
        $d = $temp % 10;   
        $new = $new * 10 + $d;   
        $temp = $temp/10;   
    }   
    if ($new == $number){   
         echo "Palindrome". $original;
		}
		else{ 
        echo "Not a Palindrome".$original; 
    }               }
?>


</body>
</html>

Output

Palindrome Program in PHP
Figure: Palindrome Program in PHP

Topic Covered

Palindrome Program in PHP.

Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.