2016-05-09 55 views
0

我想創建一個數組,其中包含所有的輸入/選擇/ textarea名稱從我提供給DOMDocument類的HTML。我不確定我做錯了什麼,但我不知道如何獲取元素的名稱。誰能幫我?這就是我一直試圖遠PHP的DOMDocument和DOMXpath - 獲取所有輸入/選擇/ textarea名

// Parse the FORM data into HTML 
$dom = new DOMDocument(); 
$dom->loadHTML($form['FORM_DATA']); 
// Use DOMXPath query to pull the input, select and textarea fields 
$xpath = new DOMXpath($dom); 
$col = $xpath->query('//input|//textarea|//select'); 
if(is_object($col)){ 
    foreach($col as $node) { 
     echo $node->nodeValue.'<br />'; 
    } 
} 

回答

0

使用此:

echo $node->getAttribute('name').'<br />';