note 51796 added to function.domnode-get-content
| From: | php-general at lists dot php dot net | Date: | Mon, 11 Apr 2005 16:41:44 +0000 |
| Subject: | note 51796 added to function.domnode-get-content | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87847@lists.php.net to get a copy of this message | ||
Here's a routine I wrote that acts like get_content() but returns embedded XHTML in the string
returned. I needed this as I was wanting to embed HTML formatting codes in my HTML (e.g.,
"<br />") and converting them to HTML entities or using CDATA was a huge hassle.
<?php
function GetContentAsString($node) {
$st = "";
foreach ($node->child_nodes() as $cnode)
if ($cnode->node_type()==XML_TEXT_NODE)
$st .= $cnode->node_value();
else if ($cnode->node_type()==XML_ELEMENT_NODE) {
$st .= "<" . $cnode->node_name();
if ($attribnodes=$cnode->attributes()) {
$st .= " ";
foreach ($attribnodes as $anode)
$st .= $anode->node_name() . "='" .
$anode-node_value() . "'";
}
$nodeText = GetContentAsString($cnode);
if (empty($nodeText) && !$attribnodes)
$st .= " />"; // unary
else
$st .= ">" . $nodeText . "</" .
$cnode->node_name() . ">";
}
return $st;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.domnode-get-content.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51796
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51796&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51796&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51796&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51796&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51796&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51796&report=yes
Search -- http://master.php.net/manage/user-notes.php