Phpxml instance message book _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.