note 102429 deleted from class.domelement by danbrown

[email protected] Mon, 14 Feb 2011 05:32:50 -0800
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: happylot.info 

----

I use this code to get content of tag, but the result return
<h1 class="Title">Some text...</h1>

    function getTags( $dom, $tagName, $attrName, $attrValue ){
        $html = '';
        $domxpath = new DOMXPath($dom);
        $newDom = new DOMDocument;
        $newDom->formatOutput = true;
        $filtered = $domxpath->query("//$tagName" . '[@' . $attrName . "='$attrValue']");
      
        $i = 0;
        while( $myItem = $filtered->item($i++) ){
            $node = $newDom->importNode( $myItem, true );    // import node
            $newDom->appendChild($node);                    // append node
        }
       
        $html = $newDom->saveHTML() ;
        return $html;
    }