PHPHtmlParser\Dom\Tag::makeOpeningTag PHP Method

makeOpeningTag() public method

Generates the opening tag for this object.
public makeOpeningTag ( ) : string
return string
    public function makeOpeningTag()
    {
        $return = '<' . $this->name;
        // add the attributes
        foreach ($this->attr as $key => $info) {
            $info = $this->getAttribute($key);
            $val = $info['value'];
            if (is_null($val)) {
                $return .= ' ' . $key;
            } elseif ($info['doubleQuote']) {
                $return .= ' ' . $key . '="' . $val . '"';
            } else {
                $return .= ' ' . $key . '=\'' . $val . '\'';
            }
        }
        if ($this->selfClosing) {
            return $return . ' />';
        } else {
            return $return . '>';
        }
    }

Usage Example

Example #1
0
 public function testMakeOpeningTagSelfClosing()
 {
     $attr = ['class' => ['value' => 'clear-fix', 'doubleQuote' => true]];
     $tag = new Tag('div');
     $tag->selfClosing()->setAttributes($attr);
     $this->assertEquals('<div class="clear-fix" />', $tag->makeOpeningTag());
 }