-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmarkword.php
84 lines (78 loc) · 1.63 KB
/
markword.php
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
<?php
$word = $_GET["word"];
$from = $_GET["from"];
$to = $_GET["to"];
if($from == $to){exit('fail: "from" and "to" should not be equal.');}
switch ($from){
case "e":
$from='./lists/myeasylist';
break;
case "h":
$from='./lists/myhardlist';
break;
case "g":
$from='./lists/mygotlist';
break;
case "o":
$from='./lists/list_orig';
break;
default:
exit("fail: argument 'from' out of range.");
}
switch ($to){
case "e":
$to='./lists/myeasylist';
break;
case "h":
$to='./lists/myhardlist';
break;
case "g":
$to='./lists/mygotlist';
break;
case "o":
$to='./lists/list_orig';
break;
default:
exit("fail: argument 'to' out of range.");
}
//print("moveing word:" . $word . "<br />");
//print("from: " . $from."<br />");
//print("to: " . $to."<br />");
if ((strlen($word)>0 and strlen($word)<25)) {
$mylist=fopen($from,"r") or exit("fail: open fail.");
$wordlist=array();
$z=0;
while(!feof($mylist)){
$wordlist[$z]=trim(fgets($mylist));
$z++;
}
fclose($mylist);
$mylist=fopen($from,"w") or exit("fail: open fail.");
$z=0;
$wordfound=0;
for($z=0;$z<count($wordlist);$z++){
if($wordlist[$z]!=$word and $wordlist!=""){
if($z<(count($wordlist)-1)){
fwrite($mylist, $wordlist[$z]."\n");
}else{
fwrite($mylist, $wordlist[$z]);
}
}else{
if ($wordlist[$z]==$word){
$wordfound++;
}
}
}
fclose($mylist);
if ($wordfound>0){
$mylist=fopen($to,"a");
fwrite($mylist, $word."\n");
fclose($mylist);
print("done!");
}else{
print("fail: word not found.");
}
}else{
exit("fail: argument out of range.");
}
?>