/
display2.php
122 lines (106 loc) · 3 KB
/
display2.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<html>
<head>
<style type="text/css">
.oneword {
display:inline;
cursor: pointer;
}
.oneword2 {
display:none;
cursor: pointer;
}
</style>
<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>-->
<script type="text/javascript">
function myclick(obj){
var nodes=obj.parentNode.childNodes;
if(nodes[0].className =="oneword"){
nodes[0].className="oneword2";
nodes[1].className="oneword";
}
else{
nodes[1].className="oneword2";
nodes[0].className="oneword";
}
}
</script>
</head>
<body align="center">
<!-- <a href = "test.php"> Back to Index </a> -->
<?php
function getQuery($name){
return 0;
}
function display_file($target_file){
$myfile = fopen($target_file, "r") or die("Unable to open file!");
$text = fread($myfile,filesize($target_file));
$lines = explode("\n", $text);
// $dict_addr = "uploads/dictionary.txt";
// $dict = fopen($dict_addr, "r") or die("Unable to open file!");
// $dict_text = fread($dict, filesize($dict_addr));
// $dict_output = preg_split('/[\ \n\,]+/', $dict_text);
// $hash = array();
$user_name = "root";
$password = "root";
$database = "dict";
$server = "localhost";
if(!$db_handle = mysql_connect($server, $user_name, $password)){
echo 'Could not connect to mysql';
exit;
}
$db_found = mysql_select_db($database, $db_handle);
if (!$db_found) {
echo "Database NOT Found ";
exit;
}
$name = explode('/', $target_file);
$num = count($name);
$title = $name[$num - 1];
echo "<p><b>$title</b></p>";
echo "<table>";
// $testt = '\'abide\'';
// $SQL = "SELECT center FROM dict_table WHERE plain = ".$testt;
// $result = mysql_query($SQL, $db_handle);
// $center = mysql_result($result, 0);
// echo $SQL;
// echo "<br />";
// $tt = Array();
// while ($row = mysql_fetch_assoc($result)) {
// $tt = $row['center'];
// }
// print_r($tt);
// mysql_free_result($result);
foreach($lines as $line){
$word_array = preg_split('/[\ \n\,]+/', $line);
echo "<br />";
foreach($word_array as $word){
// if(count($word) > 0 and (ord($word[0]) < 'a' or ord( $word[0]) > ord('z') ) )
// $SQL = "SELECT center FROM dict_table WHERE plain = ".'\''. $word. '\'';
// elseif(count($word) > 0)
// $SQL = "SELECT center FROM dict_". $word[0] ." WHERE plain = ".'\''. $word. '\'';
// else
// continue;
$SQL = "SELECT center FROM dict_table USE INDEX (search_index) WHERE plain = ".'\''. $word. '\'';
$result = mysql_query($SQL, $db_handle);
$n = mysql_num_rows($result);
$tt = Array();
while ($row = mysql_fetch_assoc($result)) {
$tt = $row['center'];
}
if ($n==0){
echo "<span><span class= 'oneword' onclick='myclick(this)' id ='$n'>$word </span><span class= 'oneword2' onclick='myclick(this)'>$word</span>
</span>";
}
else{
echo "<span><span class= 'oneword' onclick='myclick(this)'>$tt </span><span class= 'oneword2' onclick='myclick(this)'>$word</span>
</span>";
}
}
}
echo"</table>";
}
$dir = $_GET['name'];
display_file($dir);
?>
</body>
</html>