sanitize_textarea_field()WP 4.7.0

Sanitizes a multiline string from user input or from the database.

The function is like sanitize_text_field(), but preserves new lines (\n) and other whitespace, which are legitimate input in textarea elements.

1 time — 0.000098 sec (very fast) | 50000 times — 1.17 sec (fast) | PHP 7.1.2, WP 4.7.3
Hooks from the function

Return

String. Sanitized string.

Usage

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

Examples

0

#1 Demo: how the function sanitize passed string

$text = 'Check how<em>/em>
cleared > (string)    <    <br>. ';

$text = sanitize_textarea_field( $text );

var_dump( $text );

/*
string(80) "Check how
cleared > (string)    &lt;    ."
*/
var_dump( sanitize_text_field( "ビットコイン | 比特币" ) ); 
// string(30) "ビットコイン | 比特币"

Notes

Changelog

Since 4.7.0 Introduced.

sanitize_textarea_field() code WP 6.4.3

function sanitize_textarea_field( $str ) {
	$filtered = _sanitize_text_fields( $str, true );

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