Reputation: 13377
How can I read tag attributes and classes with DOMDocument, DOMNode and the rest of the family?
And, intended to be working with HTML not XML.
Maybe any useful extensions/modules to be used for this?
Thanks in advance!
Upvotes: 0
Views: 190
Reputation: 198217
Actually this is all in the PHP Manual, so I give some hints:
How can I read tag attributes and classes with DOMDocument, DOMNode and the rest of the family?
These objects have methods available to access attributes, like getAttribute
.
And, intended to be working with HTML not XML.
Use DomDocument->loadHTML()
to load HTML, this makes it very similar to XML handling.
Maybe any useful extensions/modules to be used for this?
It's all in the Dom Extension, normally you can do pretty everything with it and no additions are necessary. XPath is part of the Dom Extension as well. However there are libraries like QueryPath or FluentDom that might encapsulate a bit more what you're looking for, e.g. for classes.
Upvotes: 3
Reputation: 817228
DOMNode
[docs] has an attributes
property [docs].
Note that only DOMElement
s [docs] can actually have attributes.
Upvotes: 3