A simple program to ask the user to give a number and then it will display if the given number is a prime number or not using PHP programming language.
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 in 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.
Please subscribe to my channel https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg
Program Listing
index.php
<?php if (isset($_POST["txtNumber"])) { $MyNum = $_POST["txtNumber"]; $n = 0; for ($i = 2; $i < $MyNum; $i++) { if ($MyNum % $i == 0) { $n++; break; } } if ($n == 0) { $output = $MyNum . " is a prime number."; } else { $output = $MyNum . " is not a prime number."; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Prime Numbers in PHP</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body style="font-family:'Lucida Sans', sans-serif;"> <main class="container d-flex justify-content-center align-items-center" style="min-height: 100vh;"> <div class="card p-3"> <div class="card-body text-center"> <div class="alert alert-primary mt-2" role="alert"> <h2 class="mb-2 text-uppercase">Prime Numbers in PHP</h2> <p class="mb-0">Created By:</p> <h5 class="lh-1">» Jake R. Pomperada, MAED-IT, MIT «</h5> </div> <form class="my-3" action="" method="POST"> <div class="mb-1"> <label for="txtNumber" class="form-label">Enter a number</label> <input type="text" class="form-control form-control-sm" name="txtNumber" id="txtNumber"> </div> <button type="button" class="btn btn-primary btn-sm w-100">Submit</button> </form> <?php if (isset($output)) { echo '<div class="alert alert-primary mt-2" role="alert"> '.$output.' </div>'; } ?> </div> </div> </ma> </body> </html>
No comments:
Post a Comment