WP_HTML_Tag_Processor::get_tagpublicWP 6.2.0

Returns the uppercase name of the matched tag.

Example:

$p = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
$p->next_tag() === true;
$p->get_tag() === 'DIV';
$p->next_tag() === false;
$p->get_tag() === null;

Method of the class: WP_HTML_Tag_Processor{}

No Hooks.

Returns

string|null. Name of currently matched tag in input HTML, or null if none found.

Usage

$WP_HTML_Tag_Processor = new WP_HTML_Tag_Processor();
$WP_HTML_Tag_Processor->get_tag(): ?string;

Changelog

Since 6.2.0 Introduced.

WP_HTML_Tag_Processor::get_tag() code WP 7.1

public function get_tag(): ?string {
	if ( null === $this->tag_name_starts_at ) {
		return null;
	}

	$tag_name = str_replace( "\x00", "\u{FFFD}", substr( $this->html, $this->tag_name_starts_at, $this->tag_name_length ) );

	if ( self::STATE_MATCHED_TAG === $this->parser_state ) {
		return strtoupper( $tag_name );
	}

	/*
	 * Processing instruction targets are case-sensitive
	 * and returned as they appear in the input HTML.
	 */
	if ( self::STATE_PROCESSING_INSTRUCTION === $this->parser_state ) {
		return $tag_name;
	}

	if (
		self::STATE_COMMENT === $this->parser_state &&
		self::COMMENT_AS_PI_NODE_LOOKALIKE === $this->get_comment_type()
	) {
		return $tag_name;
	}

	return null;
}