🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

How to check the given number is either Palindrome number or not in PHP embedded in HTML? -5

How to check the given number is either Palindrome number or not in PHP?

What is the Palindrome number?

A palindrome is a word , number, phrase, verse or sentence that reads the same forward and backward.

Here , we’ll see the palindrome number:

Logic: Its logic has same like reverse number, in further we’ll check the given number and reverse number is equal or not.

  1. First of all, the remainder of $num divided by 10 is stored in the variable $rem. Now, $rem contains the last digit of $num, i.e. 1.
  2. $rem is then added to the variable $rev after multiplying it by 10.
  3. Multiplication by 10 adds a new place in the $rev contains. $rev contain like this 0 * 10 + 1 = 1.
  4. $num is then divided by 10 so that now it only contains first four digits: 1232.
  5. After second iteration, $rem equals 2, $rev equals 1 * 10 + 2 = 12 and $num = 123.
  6. After third iteration, $rem equals 3, $rev equals 12 * 10 + 3 = 123 and $num = 12.
  7. After fourth iteration, $rem equals 2, $rev equals 123 * 10 + 2 = 1232 and $num = 1.
  8. After fifth iteration, $rem equals 1, $rev equals 1232 * 10 + 1 = 12321 and $num = 0.
  9. Now, $num will be existed outside the while loop and $rev contains 12321.

Now , look at this coding

<?php
$message = '';
$message1 = '';
if (isset($_POST['num'])) {
if (!empty($_POST['num'])) {
$num = $_POST['num'];
$rev=0;
$temp =$num;
while ($temp>1) {
$rem = $temp%10;
$rev =($rev * 10) + $rem;
$temp =($temp / 10);
}
if ($num== $rev) {
$message = $num;
// echo "<h3> This is palindrome number: $rev </h3>";
$message1 = $rev;
}else{
echo "<h2>This is not palindrome number: $num</h2>";
}
}else{
echo "<h4>No text has been ebtered</h4>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Palindrome program</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel ="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css2?family=Balsamiq+Sans&display=swap" rel="stylesheet">
<style>
body{
font-size: 25px;
font-family: 'Balsamiq Sans', cursive;
background-color: #46C7C7;
}
.container{
width: 50%;
margin: 0 auto;
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
input[type=text], textarea{
width: 150%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
resize: vertical;
color: #2B3856;
}
input[type=submit]{
color: white;
padding: 15px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
float: right;
}
label{
color: #2B547E;
}
.col-6{
float: left;
width: 25%;
margin-top: 6px;
align: right;
}
.row:after{
content: " ";
display: table;
clear: both;
}
h2,h3,h4{
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<?php
if (!empty($message)) {
?>
<div class="row">
<h3> Enter number is <?php echo $message; ?></h3>
</div>
<div class="row">
<h3>This is palindrome number: <?php echo $message1; ?></h3>
</div>
<?php
} ?>
<form action="palindrome.php" method="POST">
<div>
<label>Enter the number :</label>
</div>
<div class="row">
<div class="col-6">
<textarea name="num" rows="5" cols="40"></textarea>
</div>
<div class="col-6">
<input type="submit" class="btn btn-primary btn-lg" name="submit" value="Submit">
</div>
</div>
</form>
</div>
</body>
</html>

The input number is: 12321

12321 is the palindrome number.

Another input is 1234:

1234 is not palindrome number

Thanks

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.