PHPHtmlParser\Dom::addSelfClosingTag PHP Method

addSelfClosingTag() public method

Adds the tag (or tags in an array) to the list of tags that will always be self closing.
public addSelfClosingTag ( string | array $tag )
$tag string | array
    public function addSelfClosingTag($tag)
    {
        if (!is_array($tag)) {
            $tag = [$tag];
        }
        foreach ($tag as $value) {
            $this->selfClosing[] = $value;
        }
        return $this;
    }

Usage Example

示例#1
0
 public function testLoadClosingTagAddSelfClosingTagArray()
 {
     $dom = new Dom();
     $dom->addSelfClosingTag(['mytag', 'othertag']);
     $dom->load('<div class="all"><mytag><p>Hey bro, <a href="google.com" data-quote="\\"">click here</a><othertag></div>');
     $this->assertEquals('<mytag /><p>Hey bro, <a href="google.com" data-quote="\\"">click here</a><othertag /></p>', $dom->find('div', 0)->innerHtml);
 }