How To Check Data Palindrome Or Not Using Loop In PHP

admin_img Posted By Bajarangi soft , Posted On 27-11-2020

We can check whether a number or string is a palindrome or not using loop in PHP. A number or string is said to be a palindrome if it remains same even after reversing the digits or letters.So today we implement code to check data is palindrome or not using php

How To Check Data Palindrome Or Not Using Loop In PHP

Complete Code For Checking Palindrome Or Not Using Loop In PHP.

<!DOCTYPE html>
<html>
<head>
    <title>How To Check Data Palindrome Or Not Using Loop In PHP</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<style>
    body {
        background: black;
    }

    .form-control {
        width: 80%;
    !important;
    }
</style>
<body>
<body>
<div class="container">
    <br/><br/>
    <div class="text-center">
        <h1 id="color" style="color: white;">Check Data Palindrome Or Not Using Loop In PHP</h1>
    </div>

    <div class="well">

        <form method="post">
            Enter a Number: <input class="form-control" type="text" name="number"><br><br>
            <input type="submit" class="btn btn-success" name="submit" value="Submit">
        </form>
        <?php
        if(isset($_POST['number']))
        {
            $number=$_POST['number'];

            $temp = $number;
            $new = 0;
            while (floor($temp)) {
                $d = $temp % 10;
                $new = $new * 10 + $d;
                $temp = $temp/10;
            }
            if ($new == $number){
                echo "$number is a Palindrome";
            }
            else{
                echo "$number is Not a Palindrome ";
            }
        }
        ?>
    </div>
</div>
</body>
</html

Related Post