How To Implement PHP Code To Check A Number Prime Or Not

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

A number which is only divisible by 1 and itself is called prime number. Numbers 2, 3, 5, 7, 11, 13, 17, etc. are prime numbers. 2 is the only even prime number. It is a natural number greater than 1 and so 0 and 1 are not prime numbers.

How To Implement PHP Code To Check A Number Prime Or Not

Complete Code For Implementing PHP Code To Check A Number Prime Or Not.

<!DOCTYPE html>
<html>
<head>
    <title>How To Implement PHP Code To Check A Number Prime Or Not</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;">PHP Code To Check A Number Prime Or Not</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']))
        {
            $num=$_POST['number'];
            for ($i = 2; $i <= $num-1; $i++) {
                if ($num % $i == 0) {
                    $value= True;
                }
            }
            if (isset($value) && $value) {
                echo 'The Number '. $num . ' is not prime';
            }  else {
                echo 'The Number '. $num . ' is prime';
            }
        }
        ?>
    </div>
</div>
</body>
</html>

Related Post