simple_html_dom_node::outertext PHP Method

outertext() public method

get dom node's outer text (with tag)
public outertext ( )
    function outertext()
    {
        global $debugObject;
        if (is_object($debugObject)) {
            $text = '';
            if ($this->tag == 'text') {
                if (!empty($this->text)) {
                    $text = " with text: " . $this->text;
                }
            }
            $debugObject->debugLog(1, 'Innertext of tag: ' . $this->tag . $text);
        }
        if ($this->tag === 'root') {
            return $this->innertext();
        }
        // trigger callback
        if ($this->dom && $this->dom->callback !== null) {
            call_user_func_array($this->dom->callback, array($this));
        }
        if (isset($this->_[HDOM_INFO_OUTER])) {
            return $this->_[HDOM_INFO_OUTER];
        }
        if (isset($this->_[HDOM_INFO_TEXT])) {
            return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
        }
        // render begin tag
        if ($this->dom && $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]) {
            $ret = $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]->makeup();
        } else {
            $ret = "";
        }
        // render inner text
        if (isset($this->_[HDOM_INFO_INNER])) {
            // If it's a br tag...  don't return the HDOM_INNER_INFO that we may or may not have added.
            if ($this->tag != "br") {
                $ret .= $this->_[HDOM_INFO_INNER];
            }
        } else {
            if ($this->nodes) {
                foreach ($this->nodes as $n) {
                    $ret .= $this->convert_text($n->outertext());
                }
            }
        }
        // render end tag
        if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END] != 0) {
            $ret .= '</' . $this->tag . '>';
        }
        return $ret;
    }

Usage Example

Ejemplo n.º 1
0
 function outertext()
 {
     if ($this->tag === HDOM_ROOT_PSEUDOTAG) {
         return $this->innertext();
     }
     return parent::outertext();
 }