Get contents of BODY without DOCTYPE, HTML, HEAD and BODY tags

后端 未结 7 1571
情话喂你
情话喂你 2021-02-12 17:45

What I am trying to do is include an HTML file within a PHP system (not a problem) but that HTML file also needs to be usable on its own, for various reasons, so I need to know

7条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-12 18:28

    A solution with only one instance of DOMDocument and without loops

    $d = new DOMDocument();
    $d->loadHTML(file_get_contents('/path/to/my.html'));
    $body = $d->getElementsByTagName('body')->item(0);
    echo $d->saveHTML($body);
    

提交回复
热议问题