xml 怎樣通過php解析到二維數組裡面_PHP教程

來源:互聯網
上載者:User
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...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.