Home > Backend Development > PHP Tutorial > PHP+xml method to implement online English dictionary query, xml English dictionary_PHP tutorial

PHP+xml method to implement online English dictionary query, xml English dictionary_PHP tutorial

WBOY
Release: 2016-07-13 10:09:21
Original
1294 people have browsed it

php+xml method to implement online English dictionary query, xml English dictionary

The example in this article describes the method of php+xml to implement online English dictionary query. Share it with everyone for your reference. The details are as follows:

The xml here is equivalent to a database. Implementation: Query an English word and output its Chinese meaning.

xml file (database): words.xml is as follows:

Copy code The code is as follows:



boy
Boy


girl
Girl


teacher
Teacher


beauty
Beauty

Query file: word.php

Copy code The code is as follows:

Online English-Chinese Dictionary



Please enter an English word:

Processing file: xmlprocess.php

Copy code The code is as follows:
//Create xml object
$xmldoc = new DOMDocument();
$xmldoc->load("words.xml");
//Query
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 = "The word you entered cannot be found";
}
}
}
echo $cn_word;
?>

I hope this article will be helpful to everyone’s PHP XML programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/946733.htmlTechArticleHow to implement online English dictionary query with php+xml, xml English dictionary This article describes the implementation of online English with php+xml Dictionary query method. Share it with everyone for your reference. The details are as follows:...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template