<?php Receive type look at what the user does (query, add ...) $type =$_request[' type ']; Echo $type; Exit (); Creating an XML Document Object $doc =new DOMDocument (); $doc->load ("Words.xml"); To judge if ($type = = "Query") { Gets the value entered by the user $enword =$_request[' Enword '];
Determine whether to enter the query $isEnter =false; Get all Word nodes $words = $doc->getelementsbytagname ("word"); Traversing word nodes For ($i =0 $i < $words->length; $i + +) { $word _node= $words->item ($i); Get a different language $en _word=getnodeval ($word _node, "en"); $zh _word=getnodeval ($word _node, "en"); Inquire if ($enword = = $en _word) { $isEnter =true; echo $enword. " ". Getnodeval ($word _node," en "); echo "<br/><a href= ' wordview.php ' > Return to continue query </a>"; }else if ($enword = = $zh _word) { $isEnter =true; echo $enword. " ". Getnodeval ($word _node," en "); echo "<br/><a href= ' wordview.php ' > Return to continue query </a>"; } } if (! $isEnter) { echo "Cannot query"; echo "<br/><a href= ' wordview.php ' > Return to continue query </a>"; } }else if ($type = = "Add") { Receive $enword =$_request[' Enword ']; $zhword =$_request[' Zhword ']; if (!empty ($enword) &&!empty ($zhword)) { Get root node $root = $doc->getelementsbytagname ("words")->item (0);
$word = $doc->createelement ("word"); $en = $doc->createelement ("en", $enword); $zh = $doc->createelement ("en", $zhword); to mount $root->appendchild ($word); $word->appendchild ($en); $word->appendchild ($ZH); Save XML file $doc->save ("Words.xml"); echo "Add success <br/><a href= ' wordview.php ' > Return to continue Operation </a>"; }else{
echo "Please enter a word"; echo "<br/><a href= ' wordview.php ' > Return to continue Operation </a>"; Exit (); } }else if ($type = = "Delete") {
$word =$_request[' word ']; Get all Word nodes $words = $doc->getelementsbytagname ("word"); $isEnter =false; Traversing word nodes For ($i =0 $i < $words->length; $i + +) { $word _node= $words->item ($i); Get a different language $en _word=getnodeval ($word _node, "en"); $zh _word=getnodeval ($word _node, "en"); Inquire if ($word = = $en _word | | $word = = $zh _word) { $isEnter =true; Find parent Node $word _node->parentnode->removechild ($word _node); $doc->save ("Words.xml"); echo "Delete successful <br/><a href= ' wordview.php ' > Return to continue Operation </a>"; } } if (! $isEnter) { Echo "Operation failed"; echo "<br/><a href= ' wordview.php ' > Return to continue Operation </a>"; } }else if ($type = "Modify") { Receive $enword =$_request[' Enword ']; $zhword =$_request[' Zhword ']; if (!empty ($enword) &&!empty ($zhword)) { Get all Word nodes $words = $doc->getelementsbytagname ("word"); Traversing word nodes $isEnter =false; For ($i =0 $i < $words->length; $i + +) { $word _node= $words->item ($i); Get a different language $en _word=getnodeval ($word _node, "en"); $zh _word=getnodeval ($word _node, "en"); Inquire if ($enword = = $en _word && $zhword!= $zh _word) { Modify Chinese $isEnter =true; Get ZH node $zh = $word _node->getelementsbytagname ("en")->item (0); $zh->nodevalue= $zhword; $doc->save ("Words.xml"); echo "modified successfully"; echo "<br/><a href= ' wordview.php ' > Return to continue Operation </a>"; }else if ($enword!= $en _word && $zhword = = $zh _word) { Modified because $isEnter =true; $en = $word _node->getelementsbytagname ("en")->item (0); $en->nodevalue= $enword; $doc->save ("Words.xml"); echo "modified successfully"; echo "<br/><a href= ' wordview.php ' > Return to continue Operation </a>"; } } if (! $isEnter) { echo "did not make any changes"; echo "<br/><a href= ' wordview.php ' > Return to continue Operation </a>"; } }else{ echo "Please enter the words you need to modify"; echo "<br/><a href= ' wordview.php ' > Return to continue Operation </a>"; Exit (); } }
Get the text value of a node Function Getnodeval (& $MyNode, $tagName) { Return $MyNode->getelementsbytagname ($tagName)->item (0)->nodevalue; } ?> |