note 50346 deleted from ref.dom by nlopess

From: Date: Fri, 25 Feb 2005 19:23:18 +0000
Subject: note 50346 deleted from ref.dom by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-85544@lists.php.net to get a copy of this message
Note Submitter: markciliavincenti at NOSPAM dot gmail dot com ---- The dom_to_simple_array below doesn't seem to handle tags like <br/>. I have played around with the function to make one that changes a DOM Node to HTML code, which sometimes is very useful. <?php function dom_to_html($domnode) { $domnode = $domnode->firstChild; while (!is_null($domnode)) { if (!(trim($domnode->nodeValue) == "")) { switch ($domnode->nodeType) { case XML_TEXT_NODE: { echo utf8_decode($domnode->nodeValue); break; } case XML_ELEMENT_NODE: { $tag = $domnode->nodeName; echo "<" . $tag; if ($domnode->hasAttributes()) { foreach ($domnode->attributes as $d_attribute) { echo ' ' . $d_attribute->name . '="' . utf8_decode($d_attribute->value) . '"'; } } echo ">"; break; } } if ($domnode->hasChildNodes()) { dom_to_html($domnode); echo "</" . $tag . ">"; } } else { echo "<" . $domnode->nodeName . "/>"; } $domnode = $domnode->nextSibling; } } ?>

« previous php.notes (#85544) next »