Started script. Wrote function to read wordfile and validate words.

This commit is contained in:
Douglas Muth 2016-07-10 18:41:46 -04:00
parent 02a345478b
commit 591331e48a

74
wordlist/create-wordlist.php Executable file
View file

@ -0,0 +1,74 @@
#!/usr/bin/env php
<?php
/**
* This script creates the Javascript code with the wordlist based on
* the 10,000 most used English words found at https://github.com/first20hours/google-10000-english
*
* It filters out anything less than 4 characters so we get decent words.
*/
if (php_sapi_name() != "cli") {
print "This script can only be run from the command line!\n";
exit(1);
}
/**
* Read in our wordlist and return an array with all words that
* passed validation.
*
* @param string $filename The filename
*
* @return array An array of words
*
*/
function readWordList($filename) {
$retval = array();
$fp = @fopen($filename, "r");
if (!$fp) {
throw new Exception("Could not open '$filename' for reading");
}
while ($line = fgets($fp)) {
$word = rtrim($line);
$len = strlen($word);
//
// Removing anything with less than 5 characters leaves us with 7781 words,
// just slightly more than the 7776 (6^5) words we need. What a happen coincidence!
//
if ($len < 5) {
continue;
}
$retval[] = $word;
}
fclose($fp);
return($retval);
} // End of readWordList()
/**
* Our main entry point.
*/
function main() {
$filename = "google-10000-english.txt";
$words = readWordList($filename);
} // End of main()
main();