note 96843 added to book.dom
| From: | LWC at osu1 dot php dot net | Date: | Thu, 18 Mar 2010 18:29:03 +0000 |
| Subject: | note 96843 added to book.dom | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167176@lists.php.net to get a copy of this message | ||
Here's no-#text support for the last function:
function dom_to_array($root, $showtextdata=false)
{
$result = array();
if ($root->hasAttributes())
{
$attrs = $root->attributes;
foreach ($attrs as $i => $attr)
$result[$attr->name] = $attr->value;
}
$children = $root->childNodes;
if ($children->length == 1)
{
$child = $children->item(0);
if ($child->nodeType == XML_TEXT_NODE)
{
$result['_value'] = $child->nodeValue;
if (count($result) == 1)
return $result['_value'];
else
return $result;
}
}
$group = array();
for($i = 0; $i < $children->length; $i++)
{
$child = $children->item($i);
if ($showtextdata || $child->nodeName <> '#text') {
if (!isset($result[$child->nodeName]))
$result[$child->nodeName] = dom_to_array($child);
else
{
if (!isset($group[$child->nodeName]))
{
$tmp = $result[$child->nodeName];
$result[$child->nodeName] = array($tmp);
$group[$child->nodeName] = 1;
}
$result[$child->nodeName][] = dom_to_array($child);
}
}
}
return $result;
}
----
Server IP: 69.147.83.197
Probable Submitter: 193.200.150.125
----
Manual Page -- http://www.php.net/manual/en/book.dom.php
Edit -- https://master.php.net/note/edit/96843
Del: integrated -- https://master.php.net/note/delete/96843/integrated
Del: useless -- https://master.php.net/note/delete/96843/useless
Del: bad code -- https://master.php.net/note/delete/96843/bad+code
Del: spam -- https://master.php.net/note/delete/96843/spam
Del: non-english -- https://master.php.net/note/delete/96843/non-english
Del: in docs -- https://master.php.net/note/delete/96843/in+docs
Del: other reasons-- https://master.php.net/note/delete/96843
Reject -- https://master.php.net/note/reject/96843
Search -- https://master.php.net/manage/user-notes.php