sanitize_key
Sanitizes a string key.
Description
(string) sanitize_key( (string) $key );
Keys are used as internal identifiers. Lowercase alphanumeric characters, dashes and underscores are allowed.
Returns (string)
Sanitized key
Parameters (1)
- 0. $key (string)
- String key
Usage
if ( !function_exists( 'sanitize_key' ) ) { require_once ABSPATH . WPINC . '/formatting.php'; } // String key $key = ''; // NOTICE! Understand what this does before running. $result = sanitize_key($key);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/formatting.php
- function sanitize_key( $key ) {
- $raw_key = $key;
- $key = strtolower( $key );
- $key = preg_replace( '/[^a-z0-9_\-]/', '', $key );
- /**
- * Filters a sanitized key string.
- *
- * @since 3.0.0
- *
- * @param string $key Sanitized key.
- * @param string $raw_key The key prior to sanitization.
- */
- return apply_filters( 'sanitize_key', $key, $raw_key );
- }