开发者

Best way to parse an invalid HTML in PHP

开发者 https://www.devze.com 2023-01-14 11:41 出处:网络
Is there a better approach to parse an invalid HTML then applying Tidy on it? Side Note : There are some situation when you can\'t have Ti开发者_C百科dy available.

Is there a better approach to parse an invalid HTML then applying Tidy on it?

Side Note : There are some situation when you can't have Ti开发者_C百科dy available. Regexp is also not recommended I understood for parsing html.


I would try something like this: http://php.net/manual/en/domdocument.loadhtml.php

From that page:

The function parses the HTML contained in the string source. Unlike loading XML, HTML does not have to be well-formed to load. This function may also be called statically to load and create a DOMDocument object.


SimpleHTMLDOM is known to be more lenient than PHP's native DOM functions.

0

精彩评论

暂无评论...
验证码 换一张
取 消