note 47748 deleted from ref.dom by didou
| From: | didou@php.net | Date: | Sun, 12 Mar 2006 23:59:26 +0000 |
| Subject: | note 47748 deleted from ref.dom by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-105393@lists.php.net to get a copy of this message | ||
Note Submitter: M. Gutbrod
----
If you have two nodes in a HTML DOM and you want to get all text nodes between them, you can do
someting like this:
<?php
// Start node; e.g.:
$n=$dom->lastChild->previousSibling->firstChild->nextSibling;
// End node, e.g:
$e=$dom->lastChild;
while (true) {
if ($n->nodeType===XML_TEXT_NODE) { // Add " && !$up" if it's not
XML_TEXT_NODE
echo $n->nodeValue;}
if ($n->isSameNode($e)) {
break;}
if (($n->firstChild !== NULL) && !$up) {
$n=$n->firstChild;}
elseif ($n->nextSibling !== NULL) {
$up=false;
$n=$n->nextSibling;}
elseif ($n->parentNode !== NULL) {
$up=true;
$n=$n->parentNode;}
else {
break;}}
?>