WordPress at a glance

sanitize_text_field() WP 1.0

Sanitizes a string from user input or from the database.

  • Checks for invalid UTF-8,
  • Converts single < characters to entities
  • Strips all tags
  • Removes line breaks, tabs, and extra whitespace
  • Strips octets
  • See: sanitize_textarea_field()
  • See: wp_check_invalid_utf8()
  • See: wp_strip_all_tags()
✈ 1 time = 0.000051s = very fast | 50000 times = 0.67s = very fast | PHP 7.0.2, WP 4.4.2
Hooks from function:
Return

String. Sanitized string.

Usage

sanitize_text_field( $str );
$str(string) (required)
String to sanitize.

Code of sanitize_text_field: wp-includes/formatting.php VER 5.0.1

<?php
function sanitize_text_field( $str ) {
	$filtered = _sanitize_text_fields( $str, false );

	/**
	 * Filters a sanitized text field string.
	 *
	 * @since 2.9.0
	 *
	 * @param string $filtered The sanitized string.
	 * @param string $str      The string prior to being sanitized.
	 */
	return apply_filters( 'sanitize_text_field', $filtered, $str );
}

Related Functions

From tag: sanitize_

More from category: Sanitizing, Escaping

No comments
    Hello, !     Log In . Register