note 38353 deleted from control-structures.for by didou

From: Date: Sat, 10 Jan 2004 13:58:26 +0000
Subject: note 38353 deleted from control-structures.for by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-63258@lists.php.net to get a copy of this message
Note Submitter: omert@geb-team.de ---- If someone needs to find whether a number is a prime number or not, he/she can use the following script : <? $j="2" $input = "100" //or any other number. for($x=2;$x < $input ;$x++){ if ($input % $x == 0 ) { echo "no, $input is not a prime, because it can be divided over $x . " ; $prime="0"; break ; } else { $prime = "1" ;} } if ($prime == 1 ) echo "yes, $input is a prime ." ; else echo " " ; // I know this is not the best way, but it wasn't working another way. ?> You can simply get $input with this html-script: <form name="wert" method="post" action=""> <input type="text" name="input"> <input type="submit" value="Is it a prime ?" > </form> You should insert in action the name of your php file. There is only one problem, that it takes time and you get a time out, when you have a very large number.

« previous php.notes (#63258) next »