|All requests||>||Class to convert HTML into objects.||>||Request new recommendation||>||Featured requests||>||No recommendations|
by Everton da Rosa - 7 years ago (2014-11-12)
Hello friends, I need a class that transforms the HTML code (which can be read from a string or a file) on an object, the style of the XML DOM with access to tags, attributes and content of tags.
1. by Manuel Lemos - 7 years ago (2014-11-13) Reply
What about the DOM classes that come with PHP?
2. by Everton da Rosa - 7 years ago (2014-11-13) in reply to comment 1 by Manuel Lemos Comment
You refers to XML manipulation classes? Say something look like them, but shall apply to HTML documents. Thought to use the DOM class, but could have problems with content tags with characters such as "<" for example, which documents are XML be used with CDATA markup.
3. by Manuel Lemos - 7 years ago (2014-11-13) in reply to comment 2 by Everton da Rosa Comment
Yes, DOMDocument has a loadHTML function to parse HTML.
I am not sure what is you concern with CDATA sections. I think they are like regular data sections. They are decoded but tags characters < and > are returned without special meaning, just like every other character.
Did you try that or did you have any difficulties?
4. by Everton da Rosa - 7 years ago (2014-11-18) in reply to comment 3 by Manuel Lemos Comment
Tanks, I will test the DOMDocument class.
There is this old class that can parse HTML using pure PHP and return a DOM like document structure.
For most purposes the PHP DOM extensions may be more useful but if you stumbled in a limitation of those extensions, you may want to try this package.