WP_HTML_Tag_Processor::get_attribute_names_with_prefix() – Gets lowercase names of all attributes matching a given prefix in the current tag.

You appear to be a bot. Output may be restricted

Description

Gets lowercase names of all attributes matching a given prefix in the current tag.

Note that matching is case-insensitive. This is in accordance with the spec: > There must never be two or more attributes on > the same start tag whose names are an ASCII > case-insensitive match for each other.

  • HTML 5 spec

Example:

  • $p = new WP_HTML_Tag_Processor( '<div data-ENABLED class="test" DATA-test-id="14">Test</div>' );
  • $p->next_tag( array( 'class_name' => 'test' ) ) === true;
  • $p->get_attribute_names_with_prefix( 'data-' ) === array( 'data-enabled', 'data-test-id' );
  • $p->next_tag() === false;
  • $p->get_attribute_names_with_prefix( 'data-' ) === null;

Usage

$array|null = WP_HTML_Tag_Processor::get_attribute_names_with_prefix( $prefix );

Parameters

$prefix
( string ) required – Prefix of requested attribute names.

Returns

array|null List of attribute names, or null when no tag opener is matched.

Source

File name: wordpress/wp-includes/html-api/class-wp-html-tag-processor.php


Lines:

1 to 16 of 16
  function get_attribute_names_with_prefix( $prefix ) {
    if ( $this->is_closing_tag || null === $this->tag_name_starts_at ) {
      return null;
    }

    $comparable = strtolower( $prefix );

    $matches = array();
    foreach ( array_keys( $this->attributes ) as $attr_name ) {
      if ( str_starts_with( $attr_name, $comparable ) ) {
        $matches[] = $attr_name;
      }
    }
    return $matches;
  }
 

 View on GitHub View on Trac