[英]How to select all nodes of a DOMDocument with a single DOMXpath expression?
[英]PHP DOMDocument and DOMXpath - get all input/select/textarea names
我正在嘗試創建一個數組,其中包含我提供給DOMDocument類的HTML中的所有輸入/選擇/文本區域名稱。 我不確定自己在做什么錯,但是我不知道如何獲取元素的名稱。 誰能幫我? 這是我迄今為止嘗試過的
// 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 />';
}
}
用這個:
echo $node->getAttribute('name').'<br />';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.