public static function convertDomElementToArray(\DOMElement $element, $checkPrefix = true)
    {
        $prefix = (string) $element->prefix;
        $empty = true;
        $config = array();
        foreach ($element->attributes as $name => $node) {
            if ($checkPrefix && !in_array((string) $node->prefix, array('', $prefix), true)) {
                continue;
            }
            $config[$name] = static::phpize($node->value);
            $empty = false;
        }

        $nodeValue = false;
        foreach ($element->childNodes as $node) {
            if ($node instanceof \DOMText) {
                if ('' !== trim($node->nodeValue)) {
                    $nodeValue = trim($node->nodeValue);
                    $empty = false;
                }
            } elseif ($checkPrefix && $prefix != (string) $node->prefix) {
                continue;
            } elseif (!$node instanceof \DOMComment) {
                $value = static::convertDomElementToArray($node, $checkPrefix);

                $key = $node->localName;
                if (isset($config[$key])) {
                    if (!is_array($config[$key]) || !is_int(key($config[$key]))) {
                        $config[$key] = array($config[$key]);
                    }
                    $config[$key][] = $value;
                } else {
                    $config[$key] = $value;
                }

                $empty = false;
            }
        }

        if (false !== $nodeValue) {
            $value = static::phpize($nodeValue);
            if (count($config)) {
                $config['value'] = $value;
            } else {
                $config = $value;
            }
        }

        return !$empty ? $config : null;
    }
public static function convertDomElementToArray(\DOMElement $element, $checkPrefix = true)
    {
        $prefix = (string) $element->prefix;
        $empty = true;
        $config = array();
        foreach ($element->attributes as $name => $node) {
            if ($checkPrefix && !in_array((string) $node->prefix, array('', $prefix), true)) {
                continue;
            }
            $config[$name] = static::phpize($node->value);
            $empty = false;
        }

        $nodeValue = false;
        foreach ($element->childNodes as $node) {
            if ($node instanceof \DOMText) {
                if ('' !== trim($node->nodeValue)) {
                    $nodeValue = trim($node->nodeValue);
                    $empty = false;
                }
            } elseif ($checkPrefix && $prefix != (string) $node->prefix) {
                continue;
            } elseif (!$node instanceof \DOMComment) {
                $value = static::convertDomElementToArray($node, $checkPrefix);

                $key = $node->localName;
                if (isset($config[$key])) {
                    if (!is_array($config[$key]) || !is_int(key($config[$key]))) {
                        $config[$key] = array($config[$key]);
                    }
                    $config[$key][] = $value;
                } else {
                    $config[$key] = $value;
                }

                $empty = false;
            }
        }

        if (false !== $nodeValue) {
            $value = static::phpize($nodeValue);
            if (count($config)) {
                $config['value'] = $value;
            } else {
                $config = $value;
            }
        }

        return !$empty ? $config : null;
    }
public static function convertDomElementToArray ( \ DOMElement $ element , $ checkPrefix = true ) { $ prefix = ( string ) $ element -> prefix ; $ empty = true ; $ config = array ( ) ; foreach ( $ element -> attributes as $ name => $ node ) { if ( $ checkPrefix && ! in_array ( ( string ) $ node -> prefix , array ( '' , $ prefix ) , true ) ) { continue ; } $ config [ $ name ] = static :: phpize ( $ node -> value ) ; $ empty = false ; } $ nodeValue = false ; foreach ( $ element -> childNodes as $ node ) { if ( $ node instanceof \ DOMText ) { if ( '' !== trim ( $ node -> nodeValue ) ) { $ nodeValue = trim ( $ node -> nodeValue ) ; $ empty = false ; } } elseif ( $ checkPrefix && $ prefix != ( string ) $ node -> prefix ) { continue ; } elseif ( ! $ node instanceof \ DOMComment ) { $ value = static :: convertDomElementToArray ( $ node , $ checkPrefix ) ; $ key = $ node -> localName ; if ( isset ( $ config [ $ key ] ) ) { if ( ! is_array ( $ config [ $ key ] ) || ! is_int ( key ( $ config [ $ key ] ) ) ) { $ config [ $ key ] = array ( $ config [ $ key ] ) ; } $ config [ $ key ] [ ] = $ value ; } else { $ config [ $ key ] = $ value ; } $ empty = false ; } } if ( false !== $ nodeValue ) { $ value = static :: phpize ( $ nodeValue ) ; if ( count ( $ config ) ) { $ config [ 'value' ] = $ value ; } else { $ config = $ value ; } } return ! $ empty ? $ config : null ; }
Converts a \DOMElement object to a PHP array.

The following rules applies during the conversion:

* Each tag is converted to a key value or an array
if there is more than one "value"

* The content of a tag is set under a "value" key (<foo>bar</foo>)
if the tag also has some nested tags

* The attributes are converted to keys (<foo foo="bar"/>)

* The nested-tags are converted to keys (<foo><foo>bar</foo></foo>)

@param \DOMElement $element     A \DOMElement instance
@param bool        $checkPrefix Check prefix in an element or an attribute name

@return array A PHP array
Converts a \ DOMElement object to a PHP array .