note 105273 deleted from function.domnode-get-content by thiago
| From: | thiago@php.net | Date: | Sun, 07 Aug 2011 00:38:05 +0000 |
| Subject: | note 105273 deleted from function.domnode-get-content by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-182289@lists.php.net to get a copy of this message | ||
Note Submitter: krnl
----
More common in PHP5
<?php
function getContentAsString($node)
{
$string = '';
foreach($node->childNodes as $child)
switch($child->nodeType)
{
case XML_ELEMENT_NODE:
$string .= '<'.$child->nodeName;
foreach($child->attributes as $attribute)
$string .= '
'.$attribute->name.'="'.$attribute->value.'"';
$nodeText = getContentAsString($child);
if(empty($nodeText))
$string .= '/>';
else
$string .= '>'.$nodeText.'</'.$child->nodeName.'>';
break;
case XML_TEXT_NODE:
$string .= $child->nodeValue;
break;
}
return $string;
}
?>
Greets from
http://krnl.de/