[英]PHP DOMDocument and DOMXpath - get all input/select/textarea names
I'm trying to create an array that contains all of the input/select/textarea names from the HTML I provide to the DOMDocument class. 我正在尝试创建一个数组,其中包含我提供给DOMDocument类的HTML中的所有输入/选择/文本区域名称。 I'm not sure what I'm doing wrong, but I can't figure out how to get the element's name. 我不确定自己在做什么错,但是我不知道如何获取元素的名称。 Can anyone help me? 谁能帮我? this is what I've tried to far 这是我迄今为止尝试过的
// 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.