sanitize_text_field( string $str )

Sanitizes a string from user input or from the database.


Description 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 See also


Top ↑

Parameters Parameters

$str

(string) (Required) String to sanitize.


Top ↑

Return Return

(string) Sanitized string.


Top ↑

Source 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 );
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.9.0 Introduced.

Top ↑

More Information More Information

Basic Usage

<?php sanitize_text_field( $str ) ?>


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.