Copy Code code as follows:
<?php
Open an XML file for storing messages
$guestbook = simplexml_load_file (' Db/guestbook.xml ');
foreach ($guestbook->thread as $th)//loop read every thread label in XML data
{
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 Code code as follows:
<?php
$guestbook = new DOMDocument (); To create a new DOM object
$guestbook->load (' db/guestbook.xml '); Reading XML data
$threads = $guestbook->documentelement; Get root of XML structure
Create a new thread node
$thread = $guestbook->createelement (' thread ');
$threads->appendchild ($thread);
Create a title tag on a new thread node
$title = $guestbook->createelement (' title ');
$title->appendchild ($guestbook->createtextnode ($_post[' title '));
$thread->appendchild ($title);
Create a author label on the new thread node
$author = $guestbook->createelement (' author ');
$author->appendchild ($guestbook->createtextnode ($_post[' author '));
$thread->appendchild ($author);
Create a content label on a new thread node
$content = $guestbook->createelement (' content ');
$content->appendchild ($guestbook->createtextnode ($_post[' content '));
$thread->appendchild ($content);
Writing 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 Code code as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"
"Http://www.w3.org/TR/html4/loose.dtd" >
<title> post a new message </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body>
<form name= "Form1" method= "Post" action= "post.php" >
<table width= "border=" 0 "align=" center "cellpadding=" 0 "cellspacing=" 0 ">
<tr>
<td> title </td>
<td><input name= "title" type= "text" id= "title" Size= "M" ></td>
</tr>
<tr>
<td> author </td>
<td><input name= "Author" type= "text" id= "author" size= "></td>"
</tr>
<tr>
<td> content </td>
<td><textarea name= "Content" cols= "rows=" id= "content" ></textarea></td>
</tr>
</table>
<p align= "center" >
<input type= "Submit" value= "Submit" >
<input type= "reset" value= "reset" >
</p>
</form>
</body>