WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Prime number finder (Sieve of Erastothenes)
Categories : PHP, Algorithms, Math. Click here to Update Your Picture
Chao Xu
Date : May 15th 2007
Grade : 3 of 5 (graded 2 times)
Viewed : 5177
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Chao Xu
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

This script uses Sieve of Erastothenes to find all the prime up to a number

<?php
//Made by Chao Xu
//http://webdevlogs.com/
function esprime($limit){
       
$sqrtlimit = sqrt($limit);
$range = 0;
while(
$range<$limit){
       
$i .= '11';
       
$range+=2;
}
       
$n = 2;
        while(
$n < $sqrtlimit){
                if (
$i[$n]){
                       
$sqn = $n*$n;
                       
$k = $sqn;
                       
$i[$k]=0;
                        while(
$k<=$limit){
                               
$k += $n;
                               
$i[$k]=0;
                        }
                }
                ++
$n;
        }
       
$n = 1;
        while(
$n<$limit){
                if(
$i[$n]) $primes[] = $n;
               
$n+=2;
        }
        if(
$limit>=2) $primes[0] = 2;
        return
$primes;
}
?>



It returns an array of all prime number below an the argument.
<?php
esprime
(6);
//return array(2,3,5);
?>



Library of math functions to expand the functionality of PHP3. Version 1.2.1 fixes a major problem with the gcd function.
Categories : Algorithms, PHP, Math.
Diffusion-Limited Aggregation visualization
Categories : PHP, Graphics, Algorithms, Math.
Reverse a given number
Categories : PHP, Beginner Guides, Algorithms, Math.
Show the steps for converting a number from a given base to base 10. Shows the steps involved in converting a number from a given base to base 10.
Categories : PHP, Math., Algorithms
How to judge if an integer is odd or is even in Php3?
Categories : Math., PHP, Algorithms
Function to convert Arabic numbers into Roman Numerals
Categories : Algorithms, PHP, Date Time
grab the result of any calculation you submit to the Google Calculator.
Categories : PHP, Arrays, Web Services, Regexps, Math.
How to Generate a random 8 character string in php3?
Categories : PHP, Algorithms
Credit Card Identification and Validation Class - The credit_card class provides methods for cleaning, validating and identifying the type of credit card numbers.
Categories : PHP, PHP Classes, Credit Cards, Ecommerce, Algorithms
Boolean Keyword Interpreter
Categories : PHP, Algorithms, Search Engines
Prime Spiral is a image plotted with all the primes in a number spiral.
Categories : Algorithms, Graphics, GD image library, Math.
Math operations on big numbers
Categories : PHP, Math.
Latitude-Longitude to Miles
Categories : PHP, Utilities, Math.
A recursive function to traverse a multi-dimensional array where the dimensions are not known
Categories : Arrays, PHP, Algorithms
what salt do I have to feed the crypt function with to make it work like the htpasswd command of apache?
Categories : Algorithms, PHP, Authentication