innerHTML in xPath?

后端 未结 4 534
醉话见心
醉话见心 2021-01-14 17:33

Is there a way of retrieving HTML (and JavaScript) contained in a div element?

4条回答
  •  长发绾君心
    2021-01-14 18:17

    $xml=new DOMDOCUMENT();
    @$xml->loadHTML($htmlcontents);
    $xpath=new DOMXPATH($xml);
    $nodes=$xpath->query($xpath);
    
    function getHtml($nodes) {
        $result = '';
        foreach ($nodes as $node) {
            $result .= $node->ownerDocument->saveHtml($node);
        }
    return $result;
    }
    

    Source: how to get innerhtml by classname or id using php

提交回复
热议问题