W3cubDocs

/WordPress

sanitize_text_field( string $str )

Sanitizes a string from user input or from the database.

Description

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

See also

Parameters

$str

(string) (Required) String to sanitize.

Return

(string) Sanitized string.

Source

File: wp-includes/formatting.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 );
}

Changelog

Version Description
2.9.0 Introduced.

More Information

Basic Usage

<?php sanitize_text_field( $str ) ?>

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/sanitize_text_field