Php + xml: the method for adding entries to an online English dictionary. Php + xml: how to add an entry to an online English Dictionary. This document describes how to add an entry to an online English dictionary using php + xml. We will share with you how to add entries to the online English dictionary using php + xml.
This example describes how to add an entry to an online English dictionary using php + xml. Share it with you for your reference. The details are as follows:
Next, let's go to the php + xml method for online English dictionary query. here we need to add a function, submit English words and Chinese meanings, and add the information to the xml document.
Xml file (database): words. xml
The code is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
Boy
Boy
Girl
Girl
Teacher
Instructor
Beauty
Beauty
Query and add files: words. php
The code is as follows:
Online English-Chinese Dictionary
Query English words
Add an English word
File processing: xmlprocess. php
The code is as follows:
<? Php
// Create an 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 an entry
If (! Empty ($ _ POST ['add']) {
$ En_word = $ _ POST ['en _ word'];
$ Ch_word = $ _ POST ['Ch _ word'];
// Obtain the root node
$ Words = $ xmldoc-> getElementsByTagName ("words")-> item (0 );
// Add elements and 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;
// Attach the child element to the parent element.
$ 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 help you with php + XML programming.
Examples in this article describes how to add an entry to an online English dictionary using php + xml. Share it with you for your reference...