Implementation method of php using DOM to store XML data into an array

黄舟
Release: 2023-03-16 12:00:01
Original
1301 people have browsed it

This article mainly introduces the method of using PHP to store XML data into an array using DOM. It analyzes the related operation skills of PHP based on DOM to read and parse xml data based on specific examples. Friends who need it can refer to it

The example of this article describes the method of using PHP to store XML data into an array using DOM. Share it with everyone for your reference, the details are as follows:


load("config.xml"); $roots=$doc->documentElement;//获取根节点也就是config(仅有一个) $childs=$roots->childNodes;//获取根节点下所有子节点也就是 db smarty for($i=0;$i<$childs->length;$i++){ //按照根节点下的子节点数量进行循环存入数组 $config_item=$childs->item($i); //具体获得db smarty $configs[$config_item->nodeName]=array();//将db smarty这两个子节点的名称作为数据存入数组中 $items=$config_item->childNodes; //获得db smarty下的所有子节点 for($j=0;$j<$items->length;$j++){//按照db smarty下所有子节点数进行循环将db smarty下的子节点名与值以二维数组存入 $item=$items->item($j); //通过循环获取每个db smarty 下的子节点 $configs[$config_item->nodeName][$item->nodeName]=$item->nodeValue; }//二维数组的书写 } var_dump($configs);
Copy after login

The above is the detailed content of Implementation method of php using DOM to store XML data into an array. For more information, please follow other related articles on the PHP Chinese website!

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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!