Title: WP_MatchesMapRegex::callback
Published: April 25, 2014
Last modified: May 20, 2026

---

# WP_MatchesMapRegex::callback( array $matches ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_matchesmapregex/callback/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_matchesmapregex/callback/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_matchesmapregex/callback/?output_format=md#source)

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

preg_replace_callback hook

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

 `$matches`arrayrequired

preg_replace regexp matches

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

 string

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

    ```php
    public function callback( $matches ) {
    	$index = (int) substr( $matches[0], 9, -1 );
    	return ( isset( $this->_matches[ $index ] ) ? urlencode( $this->_matches[ $index ] ) : '' );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-matchesmapregex.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-matchesmapregex.php#L86)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-matchesmapregex.php#L86-L89)

## User Contributed Notes

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