Best way to parse an invalid HTML in PHP

前端 未结 2 487
一生所求
一生所求 2020-12-09 04:44

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 Tidy available. Regexp is al

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 05:44

    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.

提交回复
热议问题