PHP DOMDocument without the DTD, head, and body tags?

前端 未结 2 580
日久生厌
日久生厌 2021-01-16 11:31

Is it possible to use the DOMDocument class and not allow it to add doc type declarations, head, and body tags? I am writing my current bit of code for a server side include

2条回答
  •  太阳男子
    2021-01-16 12:05

    What @Wrikken said or, for PHP < 5.3.6, just use a regular expression:

    $html = preg_replace('~<(?:!DOCTYPE|/?(?:html|body))[^>]*>\s*~i', '', $dom->saveHTML());
    

提交回复
热议问题