load("word
s.xml"
);
//查询
if(!empty($_POST['sub']))
{
$en_word = $_POST['enword'];
$word = $xmldoc->getElementsByTagName("en"
);
for($i
=0;$i<$word->length;$i++)
{
if($en_word==$word->item($i)->node
value){
$cn_word = $xmldoc->getElementsByTagName("ch")->item($i)->nodeValue;
break;
}else
{
$cn_word = "找不到你所输入的单词";
}
}
echo $cn_word;
}
//增加词条
if(!empty($_POST['add']))
{
$en_word = $_POST['en_word'];
$ch_word = $_POST['ch_word'];
//获取根节点
$words = $xmldoc->getElementsByTagName("words")->item(0
);
//增加元素,并添加内容
$new_word = $xmldoc->createElement("word"
);
$new_word_en = $xmldoc->createElement("en"
);
$new_word_en->nodeValue = $en_word;
$new_word_ch = $xmldoc->createElement("ch"
);
$new_word_ch->nodeValue = $ch_word;
//元素之间挂载,意思是将子元素与父元素相连
$new_word->appendChild($new_word_en
);
$new_word->appendChild($new_word_ch
);
$words->appendChild($new_word
);
//保存
$xmldoc->save("word
s.xml"
);
}
?>