Using DOMDocument, is it possible to get all elements that exists within a certain DOM?

后端 未结 1 718
面向向阳花
面向向阳花 2021-02-12 23:23

Let\'s say I have an HTML file with a lot of different elements, each having different attributes. Let\'s say I do not know beforehand how this HTML will look like.

Usin

1条回答
  •  既然无缘
    2021-02-13 00:07

    You can pass an asterisk * with getElementsByTagName() which returns all elements:

    foreach($dom->getElementsByTagName('*') as $element ){
    
    }
    

    From the Manual:

    name
    The local name (without namespace) of the tag to match on. The special value * matches all tags.

    0 讨论(0)
提交回复
热议问题