This is a basic PHP program which describes how to write palindrome number program in PHP. Below examples will help you in the better understanding of palindrome number concept in PHP programming language.
We are using the if…else statement to check whether the number is Palindrome Number or not. Copy the below code and execute it with the help of PHP compiler.
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 |
<html> <head> <title>Palindrome Number Program in PHP</title> </head> <body> <form method="post"> Enter a Number: <input type="text" name="number"> <input type="submit" value="Submit"> </form> </body> </html> <?php /** * Palindrome Number Program in PHP */ if($_POST) { //get the value from form $num = $_POST['number']; //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"; } } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.