Copy code 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) //Loop to read each thread tag in the XML data
{
echo "
Title: ".$th->title."
";
echo "
Author: ".$th ->author."
";
echo "
Content:".$th->content."
";
echo "
";
}
?>
Copy code The code is as follows:
$guestbook = new DomDocument(); //Create a new DOM object
$guestbook->load('DB/guestbook.xml'); //Read 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 the title tag on the new thread node
$title = $guestbook->createElement('title');
$title->appendChild($guestbook->createTextNode($_POST['title']));
$thread->appendChild($title);
//In new thread Create the author tag on the node
$author = $guestbook->createElement('author');
$author->appendChild($guestbook->createTextNode($_POST['author']));
$thread->appendChild($author);
//Create content tag on new thread node
$content = $guestbook->createElement('content');
$ content->appendChild($guestbook->createTextNode($_POST['content']));
$thread->appendChild($content);
//Write XML data to 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 The code is as follows:
"http://www.w3.org /TR/html4/loose.dtd">
Post a new comment
< ;/body>
http://www.bkjia.com/PHPjc/320036.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320036.htmlTechArticleCopy the code as follows: ?php //Open the XML file used to store messages $guestbook = simplexml_load_file('DB /guestbook.xml'); foreach($guestbook-thread as $th) //Loop to read XML data...