Title: WP_Token_Map::contains
Published: July 16, 2024
Last modified: February 24, 2026

---

# WP_Token_Map::contains( string $word, string $case_sensitivity ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_token_map/contains/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_token_map/contains/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_token_map/contains/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_token_map/contains/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_token_map/contains/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_token_map/contains/?output_format=md#wp--skip-link--target)

Indicates if a given word is a lookup key in the map.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_token_map/contains/?output_format=md#description)󠁿

Example:

    ```php
    true  === $smilies->contains( ':)' );
    false === $smilies->contains( 'simile' );
    ```

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_token_map/contains/?output_format=md#parameters)󠁿

 `$word`stringrequired

Determine if this word is a lookup key in the map.

`$case_sensitivity`stringoptional

Pass `'ascii-case-insensitive'` to ignore ASCII case when matching. Default `'case-
sensitive'`.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_token_map/contains/?output_format=md#return)󠁿

 bool Whether there’s an entry for the given word in the map.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_token_map/contains/?output_format=md#source)󠁿

    ```php
    public function contains( string $word, string $case_sensitivity = 'case-sensitive' ): bool {
    	$ignore_case = 'ascii-case-insensitive' === $case_sensitivity;

    	if ( $this->key_length >= strlen( $word ) ) {
    		if ( 0 === strlen( $this->small_words ) ) {
    			return false;
    		}

    		$term    = str_pad( $word, $this->key_length + 1, "\x00", STR_PAD_RIGHT );
    		$word_at = $ignore_case ? stripos( $this->small_words, $term ) : strpos( $this->small_words, $term );
    		if ( false === $word_at ) {
    			return false;
    		}

    		return true;
    	}

    	$group_key = substr( $word, 0, $this->key_length );
    	$group_at  = $ignore_case ? stripos( $this->groups, $group_key ) : strpos( $this->groups, $group_key );
    	if ( false === $group_at ) {
    		return false;
    	}
    	$group        = $this->large_words[ $group_at / ( $this->key_length + 1 ) ];
    	$group_length = strlen( $group );
    	$slug         = substr( $word, $this->key_length );
    	$length       = strlen( $slug );
    	$at           = 0;

    	while ( $at < $group_length ) {
    		$token_length   = unpack( 'C', $group[ $at++ ] )[1];
    		$token_at       = $at;
    		$at            += $token_length;
    		$mapping_length = unpack( 'C', $group[ $at++ ] )[1];
    		$mapping_at     = $at;

    		if ( $token_length === $length && 0 === substr_compare( $group, $slug, $token_at, $token_length, $ignore_case ) ) {
    			return true;
    		}

    		$at = $mapping_at + $mapping_length;
    	}

    	return false;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-token-map.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-token-map.php#L442)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-token-map.php#L442-L485)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_token_map/contains/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_token_map%2Fcontains%2F)
before being able to contribute a note or feedback.