note 67205 added to function.dom-domdocument-getelementbyid

From: Date: Mon, 05 Jun 2006 19:51:47 +0000
Subject: note 67205 added to function.dom-domdocument-getelementbyid
Groups: php.notes 
Request: Send a blank email to php-notes+get-113260@lists.php.net to get a copy of this message
OK, so maybe PHP's getElementById() is behaving according to spec, but it does not have the behaviour that people *want*... Below is a global getElementById() function (i.e. not a DOMDocument method) which recursively searches through a document for a certain id value. /* Find the first element in the document (sub)tree whose id attribute has the value $id. By default, the entire document is searched - pass a non-NULL value in $node to search only the subtree below $node. */ function getElementById(DOMDocument $doc, /*string*/ $id, DOMNode $node = NULL) { if ($node === NULL) return getElementById($doc, $id, $doc->documentElement); $children = $node->childNodes; for ($i = 0; $i < $children->length; ++$i) { $elem = $children->item($i); if (!($elem instanceof DOMElement)) continue; if ($elem->getAttribute('id') == $id) return $elem; $ret = getElementById($doc, $id, $elem); if ($ret !== NULL) return $ret; } return NULL; } ---- Server IP: 217.160.72.57 Probable Submitter: 85.181.27.189 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-getelementbyid.php Edit -- http://master.php.net/note/edit/67205 Del: integrated -- http://master.php.net/note/delete/67205/integrated Del: useless -- http://master.php.net/note/delete/67205/useless Del: bad code -- http://master.php.net/note/delete/67205/bad+code Del: spam -- http://master.php.net/note/delete/67205/spam Del: non-english -- http://master.php.net/note/delete/67205/non-english Del: in docs -- http://master.php.net/note/delete/67205/in+docs Del: other reasons-- http://master.php.net/note/delete/67205 Reject -- http://master.php.net/note/reject/67205 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#113260) next »