Refer code page, the code is as follows: htmlgt; headgt; nbsp... This article introduces a PHP crud operation for operating xml programming. for details, refer.
The html code page is as follows:
Add word
The wordpress. php file has the following code:
Load ("words. xml "); // Determine if ($ type =" query ") {// obtain the user input value $ enword = $ _ REQUEST ['enword']; // determine whether to query $ isEnter = false; // Obtain all word nodes $ words = $ doc-> getElementsByTagName ("word "); // traverse the word node for ($ I = 0; $ I <$ words-> length; $ I ++) {$ word_node = $ words-> item ($ I ); // get different languages $ en_word = getNodeVal ($ word_node, "en"); $ zh_word = getNodeVal ($ word_node, "zh "); // query if ($ enword = $ en_word) {$ isEnter = true; echo $ enword. :". getNodeVal ($ word_node, "zh"); echo"
Return to continue query ";} else if ($ enword = $ zh_word) {$ isEnter = true; echo $ enword. :". getNodeVal ($ word_node, "en"); echo"
Return to continue querying ";}} if (! $ IsEnter) {echo "cannot be queried"; echo"
Return to continue querying ";}} else if ($ type =" Add ") {// receive $ enword =$ _ REQUEST ['enword']; $ zhword = $ _ REQUEST ['zhword']; if (! Emptyempty ($ enword )&&! Emptyempty ($ zhword) {// get the root node $ root = $ doc-> getElementsByTagName ("words")-> item (0 ); $ word = $ doc-> createElement ("word"); $ en = $ doc-> createElement ("en", $ enword ); $ zh = $ doc-> createElement ("zh", $ zhword); // Mount $ root-> appendChild ($ word ); $ word-> appendChild ($ en); $ word-> appendChild ($ zh); // save the xml file $ doc-> save ("words. xml "); echo" added successfully
Return to continue operation ";} else {echo" Enter the word "; echo"
Return to continue operation "; exit () ;}} else if ($ type =" delete ") {$ word =$ _ REQUEST ['word']; // get all word nodes $ words = $ doc-> getElementsByTagName ("word"); $ isEnter = false; // traverse the word node for ($ I = 0; $ I <$ words-> length; $ I ++) {$ word_node = $ words-> item ($ I ); // get different languages $ en_word = getNodeVal ($ word_node, "en"); $ zh_word = getNodeVal ($ word_node, "zh "); // query if ($ word = $ en_word | $ word = $ zh_word) {$ isEnter = true; // find the parent node $ word_node-> parentNode-> removeChild ($ word_node); $ doc-> save ("words. xml "); echo" deleted successfully
Return to continue operation ";}} if (! $ IsEnter) {echo "operation failed"; echo"
Return to continue operation ";}} else if ($ type =" modify ") {// receive $ enword =$ _ REQUEST ['enword']; $ zhword = $ _ REQUEST ['zhword']; if (! Emptyempty ($ enword )&&! Emptyempty ($ zhword) {// get all word nodes $ words = $ doc-> getElementsByTagName ("word"); // traverse word nodes $ isEnter = false; for ($ I = 0; $ I <$ words-> length; $ I ++) {$ word_node = $ words-> item ($ I ); // get different languages $ en_word = getNodeVal ($ word_node, "en"); $ zh_word = getNodeVal ($ word_node, "zh "); // query if ($ enword ==$ en_word & $ zhword! = $ Zh_word) {// modify Chinese $ isEnter = true; // Obtain zh node $ zh = $ word_node-> getElementsByTagName ("zh")-> item (0 ); $ zh-> nodeValue = $ zhword; $ doc-> save ("words. xml "); echo" modified successfully "; echo"
Return to continue operation ";} else if ($ enword! = $ En_word & $ zhword = $ zh_word) {// modify because $ isEnter = true; $ en = $ word_node-> getElementsByTagName ("en ") -> item (0); $ en-> nodeValue = $ enword; $ doc-> save ("words. xml "); echo" modified successfully "; echo"
Return to continue operation ";}} if (! $ IsEnter) {echo "no changes made"; echo"
Return to continue operation ";}} else {echo" Enter the word to be modified "; echo"
Return to continue operation "; exit () ;}/// open-source phprm.com // Obtain the node's text value function getNodeVal (& $ MyNode, $ tagName) {return $ MyNode-> getElementsByTagName ($ tagName)-> item (0)-> nodeValue ;}
The code is as follows:
Boy
Boy
Girl
Girl
Fire
Fire
Word
Lexicon
Permanent address:
Reprint at will ~ Please bring the tutorial URL ^