Example of using DOM to store XML data into arrays in PHP: domxml
This example describes how to use DOM to store XML data into arrays in PHP. We will share this with you for your reference. The details are as follows:
<? Php $ doc = new DOMDocument ('1. 0 ', 'utf-8'); $ doc-> load ("config. xml "); $ roots = $ doc-> documentElement; // get the root node, that is, config (only one) $ childs = $ roots-> childNodes; // obtain all the child nodes under the root node, namely db smartyfor ($ I = 0; $ I <$ childs-> length; $ I ++) {// cyclically store the array $ config_item = $ childs-> item ($ I) according to the number of subnodes under the root node ); // obtain the db smarty $ configs [$ config_item-> nodeName] = array (); // store the names of the db smarty subnodes as data in the array $ items = $ config_item-> childNodes; // obtain all child nodes in the database smarty for ($ j = 0; $ j <$ items-> length; $ j ++) {// cyclically store the names and values of child nodes in db smarty into two-dimensional arrays according to the number of child nodes in db smarty $ item = $ items-> item ($ j ); // cyclically obtain the subnode $ configs [$ config_item-> nodeName] [$ item-> nodeName] = $ item-> nodeValue;} under each db smarty ;} // writing a two-dimensional array} var_dump ($ configs );
PS: Here are some online tools for xml operations for your reference:
Online XML/JSON conversion tools:
Http://tools.jb51.net/code/xmljson
Online formatting XML/online compression XML:
Http://tools.jb51.net/code/xmlformat
XMLOnline compression/formatting tools:
Http://tools.jb51.net/code/xml_format_compress
XMLCode Online formatting and beautification tools:
Http://tools.jb51.net/code/xmlcodeformat