Sunday 30 June 2019

PHP HTML DOM Parser






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?


Answer



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.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...