-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordList.php
More file actions
34 lines (31 loc) · 768 Bytes
/
WordList.php
File metadata and controls
34 lines (31 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/*
* Class to load a word list from a file. Each line of the input file should
* contain exactly one word.
*
*/
class WordList {
public $wordArray;
/*
Create a new wordlist
$fileName: A string filepath for the input data file
*/
function __construct($fileName){
$this->wordArray=array();
$wordFile = fopen($fileName,"r") or die("Unable to open data file!");
while(!feof($wordFile)) {
$word = trim(fgets($wordFile));
array_push($this->wordArray,$word);
}
}
//Check whether $word is in this WordList
function inList($word) {
$word = strtolower(trim($word));
for ($i=0; $i<count($this->wordArray);$i++){
if ($this->wordArray[$i]==$word) {
return true;
}
}
return false;
}
}