清理用户输入或者从数据库中获取的字符串。
检查是否合法的 UTF-8 字符,将 < 转换成 HTML 实体,去掉所有标签,删除所有换行符,占位符,以及额外的空格,去掉八位字节。
<?php sanitize_text_field($string); ?>
$string
(string) (required) 将要清理的字符串。
Default: None
(string)
清理之后的字符串
Since: 2.9.0
wp-includes/formatting.php.
sanitize_text_field( string $str )
清理用户输入或者从数据库中获取的字符串。具体会做如下事情:
$str
(string) 类型,此参数是必须的,表示需要处理的字符串
(string) 类型,清理后的字符串。
<?php $str = sanitize_text_field( $str ) ?>
wp-includes/formatting.php
<?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 );
}