php+xml implements the method of adding entries to the online English dictionary, xml English dictionary
The example in this article describes the method of adding entries to the online English dictionary using php+xml. Share it with everyone for your reference. The details are as follows:
Following the previous article "How to implement online English dictionary query with php+xml", here we will add a function to submit English words and Chinese meanings, and add this information to the xml document.
xml file (database): words.xml
Copy code The code is as follows:
boy
Boy
girl
Girl
teacher
Teacher
beauty
Beauty
Query and add files: words.php
Copy code The code is as follows:
Online English-Chinese Dictionary
Look up English words
Add English words
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;
}
//Add entry
if(!empty($_POST['add'])){
$en_word = $_POST['en_word'];
$ch_word = $_POST['ch_word'];
//Get the root node
$words = $xmldoc->getElementsByTagName("words")->item(0);
//Add elements and add content
$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;
//Mounting between elements means connecting child elements to parent elements
$new_word->appendChild($new_word_en);
$new_word->appendChild($new_word_ch);
$words->appendChild($new_word);
//Save
$xmldoc->save("words.xml");
}
?>
I hope this article will be helpful to everyone’s php+XML programming.
http://www.bkjia.com/PHPjc/946732.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/946732.htmlTechArticlephp+xml implements the method of adding entries to the online English dictionary, xml English dictionary This article describes the php+xml example Implement the method of adding entries to the online English dictionary. Share it with everyone for your reference...