public function generate(): string
    {
        // The tag name is required
        if ($this->getTag() === '') {
            return '';
        }

        // Generate the attribute string
        $tagAttributes = $this->generateTagAttributes();

        // When attributes are provided, add a space between the tag and the attributes
        $tagSeparator = '';
        if ($tagAttributes !== '') {
            $tagSeparator = ' ';
        }

        // Create the opening tag
        $openingTag = sprintf(
            '<%s%s%s>',
            $this->getTag(),
            $tagSeparator,
            $tagAttributes
        );

        // Create the closing tag
        $closingTag = '';
        if (! in_array($this->getTag(), self::SELF_CLOSING_TAGS)) {
            $closingTag = sprintf('</%s>', $this->getTag());
        }

        // Collect the tag information
        return $openingTag . $this->getText() . $closingTag;
    }
public function generate(): string
    {
        // The tag name is required
        if ($this->getTag() === '') {
            return '';
        }

        // Generate the attribute string
        $tagAttributes = $this->generateTagAttributes();

        // When attributes are provided, add a space between the tag and the attributes
        $tagSeparator = '';
        if ($tagAttributes !== '') {
            $tagSeparator = ' ';
        }

        // Create the opening tag
        $openingTag = sprintf(
            '<%s%s%s>',
            $this->getTag(),
            $tagSeparator,
            $tagAttributes
        );

        // Create the closing tag
        $closingTag = '';
        if (! in_array($this->getTag(), self::SELF_CLOSING_TAGS)) {
            $closingTag = sprintf('</%s>', $this->getTag());
        }

        // Collect the tag information
        return $openingTag . $this->getText() . $closingTag;
    }
public function generate ( ) : string { // The tag name is required if ( $ this -> getTag ( ) === '' ) { return '' ; } // Generate the attribute string $ tagAttributes = $ this -> generateTagAttributes ( ) ; // When attributes are provided, add a space between the tag and the attributes $ tagSeparator = '' ; if ( $ tagAttributes !== '' ) { $ tagSeparator = ' ' ; } // Create the opening tag $ openingTag = sprintf ( '<%s%s%s>' , $ this -> getTag ( ) , $ tagSeparator , $ tagAttributes ) ; // Create the closing tag $ closingTag = '' ; if ( ! in_array ( $ this -> getTag ( ) , self :: SELF_CLOSING_TAGS ) ) { $ closingTag = sprintf ( '</%s>' , $ this -> getTag ( ) ) ; } // Collect the tag information return $ openingTag . $ this -> getText ( ) . $ closingTag ; }
Generates the HTML tag with it's attributes and text.
@return string
Generates the HTML tag with it s attributes and text .