Finds the matching closing tag for an opening tag.
Description
When called while the processor is on an open tag, it traverses the HTML until it finds the matching closer tag, respecting any in-between content, including nested tags of the same name. Returns false when called on a closer tag, a tag that doesn’t have a closer tag (void), a tag that doesn’t visit the closer tag, or if no matching closing tag was found.
Source
public function next_balanced_tag_closer_tag(): bool {
$depth = 0;
$tag_name = $this->get_tag();
if ( ! $this->has_and_visits_its_closer_tag() ) {
return false;
}
while ( $this->next_tag(
array(
'tag_name' => $tag_name,
'tag_closers' => 'visit',
)
) ) {
if ( ! $this->is_tag_closer() ) {
++$depth;
continue;
}
if ( 0 === $depth ) {
return true;
}
--$depth;
}
return false;
}
Changelog
Version | Description |
---|---|
6.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.