Language: php (GeSHi-highlighted)<?php// Separate the PHP from the HTML. Use a result message to bridge the gap. /* if (isset($_POST['posted'])) { You do not need a hidden form field to tell if the action is a form POST. That is a waste of characters, use the REQUEST_METHOD.*/if ($_SERVER['REQUEST_METHOD']=="POST") { /* Using $_POST['Guess'] everytime you need to access the posted value is time consuming, relative to getting the value one time and setting a variable to hold the value. */ $guess = $_POST['Guess']; /* Also, since the form user could post anything, including malicious characters in the Guess form field...you need to filter the posted value to ensure only valid values are accepted and processed. Failing to do so at the least makes your code suseptable to XSS attacks. */ $regExPattern = "/^([-]*[1-9]+[0-9]*)|([0])$/"; // Accept only Integers preg_match($regExPattern, $guess, $arr); if (!empty($arr)) { $guess = $arr[0]; if ($guess<2) { $result = "Your number (".$guess.") is not prime."; }else{ $result = "Your number is prime."; for ($count=2;$count<$guess;$count++) { $remainder=$guess%$count; //echo "Guess: ".$guess." Count: ".$count." Remainder: ".$remainder."<br>"; if (($remainder==0) && ($count!=$guess)) { $result = "Your number (".$guess.") is not prime."; $count = $guess; // short circuit the for loop...there is no need to check further values. } } } }else{ $result = "Please enter an Interger value in the text box."; }} else { $result = "Please enter your guess.";}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head> <title>Guess Prime Numbers</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><p><? echo $result; ?></p><form method="POST" action="prime1.php"> <p>What is your number for checking prime: <input type="text" name="Guess"></p> <p><input type="submit" value="submit"></p></form></body></html>