-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordProcess.php
93 lines (68 loc) · 2.42 KB
/
wordProcess.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>personal dictionary</title>
<link href="styles.css" rel="stylesheet">
</head>
<body>
<div id="wrapper" class="hffeed">
<img src="jinshan.png" width=30% />
<h1>Result of Query</h1>
<?php
echo "<div class='hffeed2'>";
$checkCode=$_POST['checkCode'];
session_start();
if($checkCode != $_SESSION['myCheckCode']){
header("Location: wordsView.php?errno=3");
exit();
}
$type=$_REQUEST['type'];
$xmldoc=new DOMDocument();
$xmldoc->load("words.xml");
if($type=="query"){
//接受新的单词
$query_word=$_REQUEST['engword'];
$words=$xmldoc->getElementsByTagName("word");
$isEnter=false;
for($i=0;$i<$words->length;$i++){
$word=$words->item($i);
$word_en=getNodeVal($word,"en");
if($query_word==$word_en){
$isEnter=true;
echo $query_word." 对应中文是:".getNodeVal($word,"ch")."<br/>";
}
}
if(!$isEnter){
echo "<br/>查询无此词条!!";
}
echo '<a href="wordQuery.php">返回查询</a>'.' '.' ';
echo "<br/>".'<a href="dictionaryEntry.php">返回主界面</a>';
}elseif($type=="add"){
$root=$xmldoc->getElementsByTagName("words")->item(0);
$new_word=$xmldoc->createElement("word");
$new_word_en=$xmldoc->createElement("en");
$new_word_ch=$xmldoc->createElement("ch");
$new_word_en->nodeValue=$_REQUEST['engword'];
$new_word_ch->nodeValue=$_REQUEST['chword'];
$root->appendChild($new_word);
$new_word->appendChild($new_word_en);
$new_word->appendChild($new_word_ch);
$b=$xmldoc->save("words.xml");
if(!$b){
echo "添加失败!!";
}else{
echo "添加成功!!";
}
echo '<a href="wordQuery.php">返回查询</a>'.' '.' ';
echo "<br/>".'<a href="dictionaryEntry.php">返回主界面</a>';
}
function getNodeVal(&$MyNode,$tagName){
return $MyNode->getElementsByTagName($tagName)->item(0)->nodeValue;
}
echo "</div>";
?>
</div>
</body>
<html>