Palindrome Program in PHP
Palindrome Program in PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
<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
Topic Covered
Palindrome Program in PHP.