Location: PHPKode > scripts > Primes Factory > primes-factory/example2.php
<?php

require_once('primesfactory.php');

$n = $_GET['number'];

if ( strlen($n) == 0 )
{
    echo "No number was input.<br/>";
    echo "Come <a href=\"javascript:history.back(1);\">back</a> to the form and retry." ;
    return ;
}

$pf = new primesfactory ;

$pf->insert_number( $n );
$pf->go();

if ( !$pf->isok() ) $pf->display_error();
else
{
      echo "<b>The sieve of Eratosthenes</b><br/><br/><font color=#EEEE00><b>Primes</b></font> before <b>$n</b> are:<br/><br/>" ;
      
      $columns = 14 ;
      
      echo "<table style=\"padding:2px;border:1px solid #dedede;\">\n" ;
      echo "\t<tr>\n" ;
      
      for ( $i = 1 ; $i <= $n ; $i++ )
      {
            if ( $pf->isprime( $i ) ) echo "\t\t<td align=\"center\" style=\"border:1px solid black;\"><font color=#EEEE00 size=\"5\"><b>$i</b></font></td>\n";
            else echo "\t\t<td align=\"center\"><font color=#0000EE size=\"5\">$i </font></td>\n" ;
            
            echo "<td width=\"5\"><td>";
            
            if ( $i % $columns == 0 ) echo "</tr>\n\t<tr>\n" ;
      }

      echo "</table>\n" ;
      
}

?>
Return current item: Primes Factory