简体   繁体   中英

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. 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 />';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM