-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwords.class.php
More file actions
94 lines (84 loc) · 2.83 KB
/
words.class.php
File metadata and controls
94 lines (84 loc) · 2.83 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/*
* File: Words.class.php
* Description: A php script that does anything with words
* Author: Chase Willden 06/28/2013
*/
class Word{
// Declare variables
private $word;
public function __construct($wordArg){
$this->word = $wordArg;
}
public function set_word($newWord){
$this->word = $newWord;
}
public function get_word(){
return $this->word;
}
// bool: returns if word is valid
function is_valid(){
$file = file_get_contents('wordlist.txt');
$wordAry = explode("\n", $file);
$count = 0;
for ($i = 0; $i < count($wordAry); $i++){
if ($wordAry[$i] == $this->word){
$count++;
return TRUE;
break;
}
}
if ($count == 0){
return FALSE;
}
}
# TODO: create function to display word definition
// Horrible outline...Still looking at other options
function definition(){
$filename = "definitions.txt";
$word = strtoupper($this->word);
$word = $word."\n";
$fh = fopen($filename, 'r');
$olddata = fread($fh, filesize($filename));
$pos = strpos($olddata, $this->word);
$count = 3000;
$char = substr($olddata, $pos, $count);
$lineBreaks = nl2br($char);
$explode = explode("<br />", trim($lineBreaks));
$definition = "";
echo $explode[0];
for ($i = 1; $i < count($explode); $i++){
if (strtoupper($explode[$i]) == $explode[$i]){
break;
}
$definition += $explode[$i];
}
if(!strpos($olddata, $word)) {
$definition = "Error";
}
fclose($fh);
return $definiton;
}
#TODO: set this function up
// request google translation for request word
function translate($lang){
$lang = str_split($lang, 2);
// http://translate.google.com/#en/pl/hello
$url = "http://translate.google.com/#en/".$lang[0]."/".$this->word;
return $url;
}
// determins if the word and another word is an anagram or not.
function is_anagram($word2){
$word1Split = str_split($this->word);
$word2Split = str_split($word2);
sort($word1Split);
sort($word2Split);
for ($i = 0; $i < count($word1Split); $i++){
if ($word1Split[$i] != $word2Split[$i]){
return FALSE;
}
}
return TRUE;
}
}
?>