PHP Program – Palindrome number

Palindrome number is a number if you reverse the number you will get the same result, for eg., below are the palindrome numbers:
898, 909, 12321

So, to find if an entered number is a Palindrome, all you have do is reverse the number and check with the original number, if matches, then it is a Palindrome.

And in this post I am writing a PHP program to find whether an entered number is Palindrome or not.

<html>
<head>
<title>Find Palindrome number - PHP Programming</title>
</head>
<body>
	
	<h3>PHP Program to find if a number is Palindrome or not! <a href="tutorialsmade.com">Tutorialsmade.com</a></h3>
	Enter a Number <br />
	<br />
	<form method="post">
		<input type="text" name="number"/>
		<button type="submit">Check</button>
	</form>
</body>
</html>

<?php 
	
	if($_POST)
	{
		//get the post value from form
		$number = $_POST['number'];
		
		//reverse the number
		$reverse = strrev($number);
		
		//check if the number and reverse is equal
		if($number == $reverse){
			echo "<span style='color:green'>Hoorah! the number is Palindrome!!</span>";	
		}else{
			echo "<span style='color:red'>Sorry! the number is not a Palindrome!!</span>";	
		}

	}	

?>

It’s a very simple program, just read the comments in the above source code to understand each steps.

And here is the live demo,

demo

Enjoy Programming!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top