Home > Backend Development > PHP Tutorial > How to parse xml into a two-dimensional array through php_PHP tutorial

How to parse xml into a two-dimensional array through php_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-14 10:09:24
Original
952 people have browsed it

localhost1root123
$doc = new DOMDocument('1.0','utf-8');
$doc->load("config.xml");
$roots=$doc->documentElement;//Get the root node which is config (only one)
$childs=$roots->childNodes;//Get all child nodes under the root node, which is db smarty
for($i=0;$i<$childs->length;$i++){ //Loop and store the number of child nodes under the root node into the array
$config_item=$childs->item($i); //Get db smarty specifically
$configs[$config_item->nodeName]=array();//Save the names of the two sub-nodes of db smarty into the array as data
$items=$config_item->childNodes; //Get all child nodes under db smarty
for($j=0;$j<$items->length;$j++){//Loop according to the number of all child nodes under db smarty and convert the name and value of the child nodes under db smarty into a two-dimensional array Deposit
$item=$items->item($j); //Get the child nodes under each db smarty through loop
$configs[$config_item->nodeName][$item->nodeName]=$item->nodeValue;
}//Writing of two-dimensional array
}
var_dump($configs);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477693.htmlTechArticle?xml version=1.0 encoding=utf-8? configdbservicerlocalhost1/servicerrootroot/rootpw123/pw/dbsmarty/smarty/config ?php $doc = new DOMDocument(1.0,utf-8); $doc-load(config.xml); $root...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
objective-c - socket sends data in xml format
From 1970-01-01 08:00:00
0
0
0
How to parse and process HTML/XML in PHP?
From 1970-01-01 08:00:00
0
0
0
How to parse and process HTML/XML in PHP?
From 1970-01-01 08:00:00
0
0
0
How to parse and process HTML/XML using PHP?
From 1970-01-01 08:00:00
0
0
0
Update xml namespace with data from PHP form
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template