PHPHtmlParser\Dom\HtmlNode::outerHtml PHP Method

outerHtml() public method

Gets the html of this node, including it's own tag.
public outerHtml ( ) : string
return string
    public function outerHtml()
    {
        // special handling for root
        if ($this->tag->name() == 'root') {
            return $this->innerHtml();
        }
        if (!is_null($this->outerHtml)) {
            // we already know the results.
            return $this->outerHtml;
        }
        $return = $this->tag->makeOpeningTag();
        if ($this->tag->isSelfClosing()) {
            // ignore any children... there should not be any though
            return $return;
        }
        // get the inner html
        $return .= $this->innerHtml();
        // add closing tag
        $return .= $this->tag->makeClosingTag();
        // remember the results
        $this->outerHtml = $return;
        return $return;
    }

Usage Example

Esempio n. 1
0
 public function testOuterHtml()
 {
     $div = new Tag('div');
     $div->setAttributes(['class' => ['value' => 'all', 'doubleQuote' => true]]);
     $a = new Tag('a');
     $a->setAttributes(['href' => ['value' => 'http://google.com', 'doubleQuote' => false]]);
     $br = new Tag('br');
     $br->selfClosing();
     $parent = new HtmlNode($div);
     $childa = new HtmlNode($a);
     $childbr = new HtmlNode($br);
     $parent->addChild($childa);
     $parent->addChild($childbr);
     $childa->addChild(new TextNode('link'));
     $this->assertEquals('<div class="all"><a href=\'http://google.com\'>link</a><br /></div>', $parent->outerHtml());
 }
All Usage Examples Of PHPHtmlParser\Dom\HtmlNode::outerHtml