DOMNode to DOMElement in php

后端 未结 5 1469
南旧
南旧 2021-02-13 20:15

I want to convert a DOMNode object from a call to getElementsByTagName() to a DOMElement in order to access methods like getElements

5条回答
  •  后悔当初
    2021-02-13 20:54

    This is what I use in my project to minimize IDE warning.

    /**
     * Cast a DOMNode into a DOMElement
     */
        function cast_e(DOMNode $node) : DOMElement {
        if ($node) {
            if ($node->nodeType === XML_ELEMENT_NODE) {
                return $node;
            }
        }
        return null;
    }
    

提交回复
热议问题