Phpxml instance message book. Copy the code as follows :? Php open the XML file $ guestbooksimplexml_load_file (DBguestbook. xml) used to store messages; foreach ($ guestbook-threadas $ th) cyclically reads XML data
The code is as follows:
// Open the XML file used to store messages
$ Guestbook = simplexml_load_file ('Db/guestbook. XML ');
Foreach ($ guestbook-> thread as $ th) // read every thread tag in XML data cyclically
{
Echo"Title:". $ Th-> title ."
";
Echo"Author:". $ Th-> author ."
";
Echo"Content:
".$th->content."
";
Echo "";
}
?>
The code is as follows:
$ Guestbook = new DomDocument (); // create a new DOM object
$ Guestbook-> load ('Db/guestbook. XML'); // read xml data
$ Threads = $ guestbook-> documentElement; // Obtain the root of the XML structure
// Create a new thread node
$ Thread = $ guestbook-> createElement ('thread ');
$ Threads-> appendChild ($ thread );
// Create the title tag on the new thread node
$ Title = $ guestbook-> createElement ('title ');
$ Title-> appendChild ($ guestbook-> createTextNode ($ _ POST ['title']);
$ Thread-> appendChild ($ title );
// Create The author label on the new thread node
$ Author = $ guestbook-> createElement ('author ');
$ Author-> appendChild ($ guestbook-> createTextNode ($ _ POST ['author']);
$ Thread-> appendChild ($ author );
// Create the content tag on the new thread node
$ Content = $ guestbook-> createElement ('content ');
$ Content-> appendChild ($ guestbook-> createTextNode ($ _ POST ['content']);
$ Thread-> appendChild ($ content );
// Write XML data to a file
$ Fp = fopen ("DB/guestbook. xml", "w ");
If (fwrite ($ fp, $ guestbook-> saveXML ()))
Echo "message submitted successfully ";
Else
Echo "message submission failed ";
Fclose ($ fp );
?>
The code is as follows:
Http://www.w3.org/TR/html4/loose.dtd>
Post new messages
Post new messages
The http://www.bkjia.com/PHPjc/320036.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/320036.htmlTechArticle code is as follows :? Php // open the XML file used to store messages $ guestbook = simplexml_load_file ('Db/guestbook. XML'); foreach ($ guestbook-thread as $ th) // read xml data cyclically...