localhost1root123 load("config.xml");$roots=$doc->documentElement;//擷取根節點也就是config(僅有一個)$childs=$roots->childNodes;//擷取根節點下所有子節點也就是 db smartyfor($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);
http://www.bkjia.com/PHPjc/477693.htmlwww.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...