Possible Duplicate:
How to parse and process HTML with PHP?
I'm looking into HTML DOM parsers for PHP. I've found PHP Simple HTML DOM Parser. Are there any others I should be looking at?
Possible Duplicate:
How to parse and process HTML with PHP?
I'm looking into HTML DOM parsers for PHP. I've found PHP Simple HTML DOM Parser. Are there any others I should be looking at?
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Yes. Simple html doc is fine, but an order of magnitude slower than the built in dom parser.
$dom = new DOMDocument();
@$dom->loadHTML($html);
$x = new DOMXPath($dom);
foreach($x->query("//a") as $node)
{
$data['dom']['href'][] = $node->getAttribute("href");
}
Use that.
query
return a node instead of a nodelist? For example, a page has only one h1 tag. I want to get it's nodeValue, but don't think I should have to iterate through a nodelist.
– StackOverflowNewbie
Dec 2 '10 at 1:16
$node[0]
to get the first node in the list. Or just iterate and break. I just iterate and break. If the query returns nothing I don't get any errors that way.
– Byron Whitlock
Dec 2 '10 at 18:07
Recently I also found ganon, but in general PHP Simple HTML DOM Parser is the best!