note 97970 deleted from class.domelement by danbrown
| From: | danbrown@php.net | Date: | Wed, 19 May 2010 12:20:30 +0000 |
| Subject: | note 97970 deleted from class.domelement by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-169409@lists.php.net to get a copy of this message | ||
Note Submitter: Mike P Smith (mike dot smith at mehdesigns dot com)
----
Another version of patrick smith's "innerHTML" code: This shortens the foreach loop
down to one statement by taking advantage of the "ownerDocument" property of the DOMNode.
<?php
$innerHTML = '';
$doc = new DOMDocument();
$doc->loadHTMLFile($filepath);
$elem = $doc->getElementById($elem_id);
// loop through all childNodes, getting html
foreach ($elem->childNodes as $child) {
$innerHTML .= $child->ownerDocument->saveXML($child);
}
?>