note 50349 deleted from ref.dom by didou

From: Date: Sat, 02 Apr 2005 20:49:26 +0000
Subject: note 50349 deleted from ref.dom by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-87368@lists.php.net to get a copy of this message
Note Submitter: markciliavincenti at NOSPAM dot gmail dot com ---- There was a problem with the code I posted in that it didn't allow for empty tags with attributes (eg <img src="test.gif"/>) Here is the updated code: <?php function dom_to_html($domnode) { $temp = ''; $domnode = $domnode->firstChild; while (!is_null($domnode)) { if (!(trim($domnode->nodeValue) == "")) { switch ($domnode->nodeType) { case XML_TEXT_NODE: { $temp .= utf8_decode($domnode->nodeValue); break; } case XML_ELEMENT_NODE: { $tag = $domnode->nodeName; $temp .= "<" . $tag; if ($domnode->hasAttributes()) { foreach ($domnode->attributes as $d_attribute) { $temp .= ' ' . $d_attribute->name . '="' . utf8_decode($d_attribute->value) . '"'; } } $temp .= ">"; break; } } if ($domnode->hasChildNodes()) { $temp .= dom_to_html($domnode); $temp .= "</" . $tag . ">"; } } else { $temp .= "<" . $domnode->nodeName; if ($domnode->hasAttributes()) { foreach ($domnode->attributes as $d_attribute) { $temp .= ' ' . $d_attribute->name . '="' . utf8_decode($d_attribute->value) . '"'; } } $temp .= "/>"; } $domnode = $domnode->nextSibling; } return $temp; } ?>

« previous php.notes (#87368) next »