Copy CodeThe code is as follows:
Open the XML file for storing messages
$guestbook = simplexml_load_file (' Db/guestbook.xml ');
foreach ($guestbook->thread as $th)//iterate through each thread label in the XML data
{
echo "
Title:". $th->title."
";
echo "
Author:". $th->author."
";
echo "
content:
". $th->content."
";
echo "";
}
?>
Copy CodeThe code is as follows:
$guestbook = new DomDocument (); To create a new DOM object
$guestbook->load (' db/guestbook.xml '); Reading XML data
$threads = $guestbook->documentelement; Get the root of the XML structure
Create a new thread node
$thread = $guestbook->createelement (' thread ');
$threads->appendchild ($thread);
Create a title tag on the 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 CodeThe code is as follows:
"Http://www.w3.org/TR/html4/loose.dtd" >
<title>Post a new message</title>
Post a new message
http://www.bkjia.com/PHPjc/320036.html www.bkjia.com true http://www.bkjia.com/PHPjc/320036.html techarticle Copy the code as follows:? PHP//Open the XML file used to store the message $guestbook = simplexml_load_file (' Db/guestbook.xml '); foreach ($guestbook-thread As $th)//loop-read XML data ...