獲取PHP DOMDocument的子項我正在試圖獲取PHP DOMDocument的子項。說我有一個DOM文檔是這樣的:如何通過索引
<div>
<h1 ></h1>
<div id=2></div>
<div class="test"></div>
...
</div>
我有一個索引號3.然後我需要的元素<div class="test"></div>
。在DOMDocument API中,沒有像children(3)
這樣的方法。在那兒?我怎樣才能得到一個索引的孩子?
你需要使用getElementByTag( 'DIV'),然後使用getAttribute( '類'),並把在if條件匹配類= '測試'。它確實需要一點RnD – 2011-05-18 07:14:29
*(相關)* [最佳方法解析HTML](http://stackoverflow.com/questions/3577641/best-methods-to-parse-html/3577662#3577662)和[Noob問題關於在DOM中的DOMDocument](http://stackoverflow.com/questions/4979836/noob-question-about-domdocument-in-php/4983721#4983721) – Gordon 2011-05-18 07:17:26
可能的重複[如何通過Domdocument PHP獲得第一級dom元素? ](http://stackoverflow.com/questions/5882433/how-get-first-level-of-dom-elements-by-domdocument-php) – Gordon 2011-05-18 07:22:39