How to Create Prime Number calculator Using PHP Code?

Hi friends, today I will tell you through this blog how you can create prime numbers calculator with the help of PHP Script code. So let’s go guys.

How to Create Prime Number calculator Using PHP Code?I will try to tell you through php. I will try to explain you in 2 steps.

Step 1:- Create HTML Page with input form.
Step 2:- PHP Code add for Get Input Value of Prime Number.

Step 1:- Create HTML Page with input form.

```<!DOCTYPE html>
<html>
<title>Prime Number Calculator Using PHP Script Code</title>
<body>
<h1>Prime Number Calculator Using PHP Script Code</h1>
<form method="post">
Enter a Number: <input type="text" name="input"><br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>```

Step 2:- PHP Code add for Get Input Value of Prime Number.

```<?php
if(\$_POST)
{
\$num=\$_POST['input'];
for (\$i = 2; \$i <= \$num-1; \$i++) {
if (\$num % \$i == 0) {
\$value = True;
}
}
if (isset(\$value) && \$value) {
echo '<h2>The Number '. \$num . ' is not prime</h2>';
} else {
echo '<h2>The Number '. \$num . ' is prime</h2>';
}
}
?>```

We can also create this code by writing in single php page. The code for this is given below. How to write code in single page.

```<!DOCTYPE html>
<html>
<title>Prime Number Calculator Using PHP Script Code</title>
<body>
<h1>Prime Number Calculator Using PHP Script Code</h1>
<form method="post">
Enter a Number: <input type="text" name="input"><br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
if(\$_POST)
{
\$num=\$_POST['input'];
for (\$i = 2; \$i <= \$num-1; \$i++) {
if (\$num % \$i == 0) {
\$value = True;
}
}
if (isset(\$value) && \$value) {
echo '<h2>The Number '. \$num . ' is not prime</h2>';
} else {
echo '<h2>The Number '. \$num . ' is prime</h2>';
}
}
?>```