sanitize_text_field

Sanitizes a string from user input or from the database.

Description

(string) sanitize_text_field( (string) $str ); 

- Checks for invalid UTF-8, - Converts single < characters to entities - Strips all tags - Removes line breaks, tabs, and extra whitespace - Strips octets

Returns (string)

Sanitized string.

Parameters (1)

0. $str (string)
String to sanitize.

Usage

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

Defined (1)

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

/wp-includes/formatting.php  
  1. function sanitize_text_field( $str ) { 
  2. $filtered = _sanitize_text_fields( $str, false ); 
  3.  
  4. /** 
  5. * Filters a sanitized text field string. 
  6. * @since 2.9.0 
  7. * @param string $filtered The sanitized string. 
  8. * @param string $str The string prior to being sanitized. 
  9. */ 
  10. return apply_filters( 'sanitize_text_field', $filtered, $str );