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

  1. if ( !function_exists( 'sanitize_key' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // String key 
  5. $key = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = sanitize_key($key); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/formatting.php  
  1. function sanitize_key( $key ) { 
  2. $raw_key = $key; 
  3. $key = strtolower( $key ); 
  4. $key = preg_replace( '/[^a-z0-9_\-]/', '', $key ); 
  5.  
  6. /** 
  7. * Filters a sanitized key string. 
  8. * @since 3.0.0 
  9. * @param string $key Sanitized key. 
  10. * @param string $raw_key The key prior to sanitization. 
  11. */ 
  12. return apply_filters( 'sanitize_key', $key, $raw_key );