get complete 'div' content using class name or id using php

后端 未结 3 1518
臣服心动
臣服心动 2020-12-18 16:21

i got a page source from a file using php and its output is similar to

3条回答
  •  余生分开走
    2020-12-18 16:35

    Try this:

    $html = <<
        
    check
    ; HTML; $dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $div = $xpath->query('//div[@class="under"]'); $div = $div->item(0); echo $dom->saveXML($div);

This will output:

check

提交回复
热议问题