PHP: DomElement->getAttribute

前端 未结 4 579
失恋的感觉
失恋的感觉 2020-12-04 01:52

How can I take all the attribute of an element? Like on my example below I can only get one at a time, I want to pull out all of the anchor tag\'s attribute.



        
4条回答
  •  不知归路
    2020-12-04 02:23

    $length = $a->attributes->length;
    $attrs = array();
    for ($i = 0; $i < $length; ++$i) {
        $name = $a->attributes->item($i)->name;
        $value = $a->getAttribute($name);
    
        $attrs[$name] = $value;
    }
    
    
    print_r($attrs);
    

提交回复
热议问题