Copy codeThe 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 every thread tag in XML data cyclically
{
Echo "<B> title: </B>". $ th-> title. "<BR> ";
Echo "<B> author: </B>". $ th-> author. "<BR> ";
Echo "<B> content: </B> <PRE>". $ th-> content. "</PRE> ";
Echo "<HR> ";
}
?>
Copy codeThe Code is as follows:
<? Php
$ 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 );
?>
Copy codeThe Code is as follows:
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"
Http://www.w3.org/TR/html4/loose.dtd>
<Html>
<Head>
<Title> post a new message </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>
<Body>
<H1> <p align = "center"> post new messages </p> </H1>
<Form name = "form1" method = "post" action = "Post. php">
<Table width = "500" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Tr>
<Td> title </td>
<Td> <input name = "title" type = "text" id = "title" size = "50"> </td>
</Tr>
<Tr>
<Td> author </td>
<Td> <input name = "author" type = "text" id = "author" size = "20"> </td>
</Tr>
<Tr>
<Td> content </td>
<Td> <textarea name = "content" cols = "50" rows = "10" id = "content"> </textarea> </td>
</Tr>
</Table>
<P align = "center">
<Input type = "submit" value = "Submit">
<Input type = "reset" value = "Reset">
</P>
</Form>
</Body>
</Html>