欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php+xml實(shí)現(xiàn)在線英文詞典查詢的方法

 更新時(shí)間:2015年01月23日 14:58:13   投稿:shichen2014  
這篇文章主要介紹了php+xml實(shí)現(xiàn)在線英文詞典查詢的方法,通過將XML文件作數(shù)據(jù)庫實(shí)現(xiàn)查詢英文對應(yīng)漢字的功能,需要的朋友可以參考下

本文實(shí)例講述了php+xml實(shí)現(xiàn)在線英文詞典查詢的方法。分享給大家供大家參考。具體如下:

這里的xml相當(dāng)于一個(gè)數(shù)據(jù)庫。實(shí)現(xiàn):查詢某個(gè)英文單詞,輸出它的中文意思。

xml文件(數(shù)據(jù)庫):words.xml如下:

復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<words>
<word>
 <en>boy</en>
 <ch>男孩</ch>
</word>
<word>
 <en>girl</en>
 <ch>女孩</ch>
</word>
<word>
 <en>teacher</en>
 <ch>老師</ch>
</word>
<word>
 <en>beauty</en>
 <ch>美女</ch>
</word>
</words>

查詢文件:word.php

復(fù)制代碼 代碼如下:
<h2>在線英漢詞典</h2>
<form action="xmlprocess.php" method="post">
請輸入英文單詞:<input type="text" name="enword" />
<input type="submit" value="查詢" name="sub">
</form>

處理文件:xmlprocess.php

復(fù)制代碼 代碼如下:
<?php
//創(chuàng)建xml對象
$xmldoc = new DOMDocument();
$xmldoc->load("words.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)->nodeValue){
   $cn_word = $xmldoc->getElementsByTagName("ch")->item($i)->nodeValue;
   break;
  }else{
   $cn_word = "找不到你所輸入的單詞";
  }
 }
}
echo $cn_word;
?>

希望本文所述對大家的php操作XML程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論