edynas Posted April 19, 2010 Share Posted April 19, 2010 I am loading HTML in as a DOM object. I want to get all the attributes of the input fields of the third form. This is what I got $dom = new domDocument; $dom->loadHTML($result); $dom->preserveWhiteSpace = false; $forms = $dom->getElementsByTagName('form'); $fields = $forms->item(2)->getElementsByTagName('input'); foreach ($fields as $field) { $x=$field->attributes->getNamedItem("value"); echo $x; } I know by echoing the $field->nodeName; that I have the right form and field does indeed holds my input fields. But I just can't seem to get the attributes. As I am getting an error saying "Object of class DOMAttr could not be converted to string". Am I overlooking something? Normally I would use a dirty split/explode/cleanup way to retrieve my wanted values but I am looking into DOM to make it more cleaner. Edwin Link to comment https://forums.phpfreaks.com/topic/198989-attributes-of-an-element-in-dom-object-loadhtml/ Share on other sites More sharing options...
edynas Posted April 19, 2010 Author Share Posted April 19, 2010 Solved..found out I need this $x = $field->getAttribute('the_att_name'); Link to comment https://forums.phpfreaks.com/topic/198989-attributes-of-an-element-in-dom-object-loadhtml/#findComment-1044494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.