Created
January 10, 2012 22:19
-
-
Save Cale/1591559 to your computer and use it in GitHub Desktop.
Write x number of random email addresses to file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This script generates x number of random email addresses | |
// and outputs them to a CSV file. | |
// Modified version of http://www.laughing-buddha.net/php/email | |
// Number of emails you'd like to generate | |
$count = 13575; | |
// Open the file we're outputing to. (This file should exist before you run the script.) | |
$fp = fopen('emails.csv', 'w'); | |
// Array of possible domains | |
$tlds = array("com", "net", "gov", "org", "edu", "biz", "info"); | |
// String of possible characters | |
$char = "0123456789abcdefghijklmnopqrstuvwxyz"; | |
// main loop | |
for ($j = 0; $j < $count; $j++) { | |
// choose random lengths for the username ($ulen) and the domain ($dlen) | |
$ulen = mt_rand(5, 10); | |
$dlen = mt_rand(7, 17); | |
// reset the address | |
$a = ""; | |
// get $ulen random entries from the list of possible characters | |
// these make up the username (to the left of the @) | |
for ($i = 1; $i <= $ulen; $i++) { | |
$a .= substr($char, mt_rand(0, strlen($char)), 1); | |
} | |
$a .= "@"; | |
// now get $dlen entries from the list of possible characters | |
// this is the domain name (to the right of the @, excluding the tld) | |
for ($i = 1; $i <= $dlen; $i++) { | |
$a .= substr($char, mt_rand(0, strlen($char)), 1); | |
} | |
// need a dot to separate the domain from the tld | |
$a .= "."; | |
// finally, pick a random domain and stick it on the end | |
$a .= $tlds[mt_rand(0, (sizeof($tlds)-1))]; | |
//echo $a."\n"; | |
$a = $a."\n"; | |
// Write to file | |
fwrite($fp,$a); | |
} | |
// Close the file | |
fclose($fp); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment