note 80200 added to ref.dom

From: Date: Fri, 04 Jan 2008 01:06:36 +0000
Subject: note 80200 added to ref.dom
Groups: php.notes 
Request: Send a blank email to php-notes+get-134736@lists.php.net to get a copy of this message
The following can take a XML_TEXT_NODE node and return the contents in an array. Yanick's contribution rocks - but it overwrote with duplicates only keeping the last line in the returned array. All the other functions i tested from various sources failed to handle text nodes correctly. Hope this helps someone. It is adapted from code on this site. function myTextNode($n, &$a) { static $depth = 0; static $sz = ''; if ($cn = $n->firstChild) { while ($cn) { if ($cn->nodeType == XML_TEXT_NODE) { $sz .= $cn->nodeValue; } elseif ($cn->nodeType == XML_ELEMENT_NODE) { $b = 1; if ($cn->hasChildNodes()) { $depth++; if ($this->myHeadings($cn, $a)) { if ($sz){ array_push($a, $sz); $sz = ''; } } $depth--; } } $cn = $cn->nextSibling; } return $b; } } so you could use: $nodes = $dom->getElementsByTagName("td"); if($nodes){ foreach ($nodes as $node){ $a = Array(); myTextNode($node, $a); } } ---- Server IP: 203.16.234.20 Probable Submitter: 220.101.138.251 ---- Manual Page -- http://www.php.net/manual/en/ref.dom.php Edit -- https://master.php.net/note/edit/80200 Del: integrated -- https://master.php.net/note/delete/80200/integrated Del: useless -- https://master.php.net/note/delete/80200/useless Del: bad code -- https://master.php.net/note/delete/80200/bad+code Del: spam -- https://master.php.net/note/delete/80200/spam Del: non-english -- https://master.php.net/note/delete/80200/non-english Del: in docs -- https://master.php.net/note/delete/80200/in+docs Del: other reasons-- https://master.php.net/note/delete/80200 Reject -- https://master.php.net/note/reject/80200 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134736) next »