这篇文章主要介绍了PHP实现使用DOM将XML数据存入数组的方法,结合具体实例形式分析了php基于DOM实现xml数据读取与解析相关操作技巧,需要的朋友可以参考下
本文实例讲述了PHP实现使用DOM将XML数据存入数组的方法。分享给大家供大家参考,具体如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php
$doc = new DOMDocument('1.0','utf-8');
$doc ->load( "config.xml" );
$roots = $doc ->documentElement;
$childs = $roots ->childNodes;
for ( $i =0; $i < $childs ->length; $i ++){
$config_item = $childs ->item( $i );
$configs [ $config_item ->nodeName]= array ();
$items = $config_item ->childNodes;
for ( $j =0; $j < $items ->length; $j ++){
$item = $items ->item( $j );
$configs [ $config_item ->nodeName][ $item ->nodeName]= $item ->nodeValue;
}
}
var_dump( $configs );
|
Salin selepas log masuk
Atas ialah kandungan terperinci php使用DOM将XML数据存入数组的实现方法. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!