PHP: DomElement->getAttribute

前端 未结 4 574
失恋的感觉
失恋的感觉 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:13

    $html = $data['html'];
    if(!empty($html)){
       $doc = new DOMDocument();
       $doc->loadHTML($html);
       $doc->saveHTML();
       $datadom = $doc->getElementsByTagName("input");
       foreach($datadom as $element)
       {
           $class =$class." ".$element->getAttribute('class');
       }
    }
    

提交回复
热议问题