PHP Classes

File: example2.php

Recommend this page to a friend!
  Classes of Alessandro Rosa   Primes Factory   example2.php   Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: example of Erathostenes' sieve
Class: Primes Factory
Perform calculations with prime numbers
Author: By
Last change:
Date: 17 years ago
Size: 1,147 bytes
 

Contents

Class file image Download
<?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" ;
     
}

?>