Sunday, February 21, 2021

Prime Number Checker in PHP

 A simple prime number check written using PHP, HTML and CSS I hope you will find my work useful.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod City I also accepting computer repair, networking, and Arduino Project development at a very affordable price. My website is www.jakerpomperada.blogspot.com and www.jakerpomperada.com

If you like this video please click the LIKE button, SHARE, and SUBSCRIBE to my channel.

Your support on my channel is highly appreciated.

Thank you very much.





Program Listing


style.css

* {

    box-sizing: border-box;

}


body {

    font-family: "Calibri", sans-serif;

    background: #e2e1e0;

    color: #111;

}


main {

    position: absolute;

    top: 50%;

    left: 50%;

    transform: translate(-50%, -50%);

}


.container {

    padding: 50px;

    width: 600px;

    background: #fff;

    text-align: left;

    border-radius: 20px;

    box-shadow: 0 0 60px rgba(0,0,0,0.05);

}


h1 {

    margin: 0;

    line-height: 0.9;

}


h2 {

    margin: 0;

}


.title {

    display: block;

    margin: 0 0 40px;

    text-align: center;

}


.txtbox {

    display: block;

    background: #f1f1f1;

    width: 100%;

    margin: 0 0 20px 0;

    padding: 15px;

    border: none;

    font-size: 20px;

    border-radius: 8px;

    font-family: "Calibri", sans-serif;

    text-align: center;

}


.txtbox:hover,

.txtbox:focus {

    background: #e0e0e0;

}


.btnWrapper {

    display: inline-flex;

}


.btn {

    background: #673ab7;

    color: #fff;

    padding: 15px;

    width: 250px;

    opacity: 0.9;

    outline: none;

    font-size: 20px;

    text-transform: uppercase;

    border: none;

    text-decoration: none;

    text-align: center;

    font-family: "Calibri", sans-serif;

    cursor: pointer;

    text-decoration: none;

    display: block;

}


.btn:hover {

    opacity: 1;

}


.btnReset {

    background: #ff5722;

    border-radius: 8px 0 0 8px;

}


.btnConvert {

    border-radius: 0 8px 8px 0;

}


.answer {

    width: 100%;

    padding: 20px;

    text-align: center;

    font-size: 25px;

    font-weight: bold;

    background: #9e9e9e;

    color: #fff;

    line-height: 1;

    margin-top: 20px;

    border-radius: 8px;

}


index.php


<?php

    $out = $input = "";

    if ($_POST) {

        $input=$_POST['txtNum'];


        for ($i = 2; $i <= $input-1; $i++) {

            if ($input % $i == 0) {

                $value= true;

            }

        }

        if (empty($value) && $input != 1) {

            $out = '<div class="answer">'.$input.' is a Prime Number </div>';

        }  else {

            $out = '<div class="answer">'.$input.' is not a Prime Number</div>';

        }

    }

?>

<!DOCTYPE html>

<html lang="en">

    <head>

        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Prime Number Checker in PHP</title>

        <link rel="stylesheet" href="style.css">

    </head>

    <body>

        <main>

            <div class="container">

                <div class="title">

                    <h1>Prime Number Checker in PHP</h1>

                    <h2>&#187; Jake R. Pomperada, MAED-IT, MIT &#171;</h2>

                </div>


                <div class="container-wrapper">

                    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" class="frmChecker">

                        <input type="number" class="txtbox" name="txtNum" id="txtNum" value="<?php echo $input; ?>" placeholder="Input a number" required autofocus>

                        

                        <div class="btnWrapper">

                            <a href="index.php" class="btn btnReset" name="btnReset">Reset</a>

                            <button type="submit" class="btn btnConvert" name="btnConvert">Check</button>

                        </div>


                        <?php echo $out; ?>

                    </form>

                </div>

            </div>

        </main>

    </body>

</html>


No comments:

Post a Comment