note 89802 modified in book.dom by danbrown
| From: | danbrown@php.net | Date: | Tue, 24 Mar 2009 13:09:54 +0000 |
| Subject: | note 89802 modified in book.dom by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152379@lists.php.net to get a copy of this message | ||
Hello,
Here's another way you can get the inner and outer html content of a element:
<?php
// code taken from the Raxan PDI framework
// returns the html content of an element
protected function nodeContent($n, $outer=false) {
$d = new DOMDocument('1.0');
$b = $d->importNode($n->cloneNode(true),true);
$d->appendChild($b); $h = $d->saveHTML();
// remove outter tags
if (!$outer) $h = substr($h,strpos($h,'>')+1,-(strlen($n->nodeName)+4));
return $h;
}
?>
There are lots of other PHP DOM manipulation and traversing APIs available at the website. See here
http://raxanpdi.com/pdi-overview.html
--was--
Hello,
Here's another way you can get the inner and outer html content of a element:
// code taken from the Raxan PDI framework
// returns the html content of an element
protected function nodeContent($n, $outer=false) {
$d = new DOMDocument('1.0');
$b = $d->importNode($n->cloneNode(true),true);
$d->appendChild($b); $h = $d->saveHTML();
// remove outter tags
if (!$outer) $h = substr($h,strpos($h,'>')+1,-(strlen($n->nodeName)+4));
return $h;
}
There are lots of other PHP DOM manipulation and traversing APIs available at the website. See here
http://raxanpdi.com/pdi-overview.html
http://php.net/manual/en/book.dom.php