Jump to content

Attributes of an element in DOM object loadHTML


edynas

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.