PHP 获取 DOM 节点的 innerHTML

dom 没 innerHTML 方法,直接 $dom->saveXML($node) 获取的相当于 outerHTML。所以得小折腾一下。

$e = $dom->getElementById('sample');
$content = '';
foreach ($e->childNodes as $node) {
    $content.= $dom->saveXML($node);


4 thoughts on “PHP 获取 DOM 节点的 innerHTML

    1. 小陶

      $content.= $dom->saveXML($node); 这句报错(Warning: Invalid argument supplied for foreach());


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.