note 76182 deleted from function.dom-domelement-construct by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Nov 2008 21:55:47 +0000 |
| Subject: | note 76182 deleted from function.dom-domelement-construct by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147280@lists.php.net to get a copy of this message | ||
Note Submitter: "Dennis Shearin"
----
I'm just starting to get into the DOM methods and finding it pretty challenging.
One of the obstacles is that once you've got a node, there doesn't seem to be any way to
see what's inside it (at least I haven't been able to find it). You'd expect (I did)
print_r to show you the properties (attributes) of the node, but all it tells you is the object
type.
So I wrote this little function to mimic the way I think print_r should work:
<?php
function nodeDump($node)
{
$output = print_r($node, TRUE);
$output = str_replace(")\n", '', $output);
$output .= ' ' . '[tagName] => ' . $node->tagName . " \n";
$numOfAttribs = $node->attributes->length;
for ($i = 0; $i < $numOfAttribs; $i++)
{
$output .= ' [' . $node->attributes->item($i)->nodeName . '] =>
' . $node->attributes->item($i)->nodeValue . " \n";
}
$output .= ' [nodeValue] => ' . $node->nodeValue;
$output .= ')';
return $output;
}
?>
OK - to really work like print_r it would also go through all the childNodes recursively, but
it's a start.