Php performs simple addition, deletion, modification, and query (CRUD) Operations on xml.

Source: Internet
Author: User
Php performs a simple addition, deletion, modification, and query (CRUD) operation on xml, assuming the following xml file exists:

 

 

  
   
Setting1 value

  

  
   
Setting2 value

  

  
   
Setting3 value

  ............

 

How to use php to perform CRUD on it? In fact, it is better to use SimpleXMl for such simple xml files. You can operate on it like this:

// CREATE $ config = new SimpleXmlElement ('

 '); $ Config-> setting1 = 'setting1 value'; $ config-> saveXML ('config. XML'); // READ $ config = new SimpleXmlElement ('config. xml '); echo $ config-> setting1; echo $ config-> asXml (); // UPDATE $ config-> setting1 = 'New Value '; $ config-> setting2 = 'setting2 value'; echo $ config-> asXml (); // DELETEunset ($ config-> setting1); $ config-> setting2 = NULL; echo $ config-> asXML (); unlink ('config. XML ');

For more details, go to the official PHP usage examples and API description.

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.