sanitize_text_field()清理用户输入或者从数据库中获取的字符串

目录

描述

清理用  或者从数据库中获取的 符串。

检查  法的 UTF-8 字符,将 < 转换成 HTML  体,去掉所有标签,  所有换行 ,占位符, 及额外的空格,去掉八位字节。

sanitize_text_field() 描述

用法

<?php sanitize_text_field$str ?>

sanitize_text_field() 用法

参数

$str

(string) (必填)  要清  符串。

默认值: None

sanitize_text_field() 参数

返回值

(string

清理之后的 符串

sanitize_text_field() 返回值

历史

  • 添加于 版本: 2.9.0

sanitize_text_field() 历史

源文件

sanitize_text_field() 函数的代码位于 wp-includes/formatting.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Sanitize a string from user input or from the db
 *
 * check for invalid UTF-8,
 * Convert single < characters="" to="" entity,="" *="" strip="" all="" tags,="" *="" remove="" line="" breaks,="" tabs="" and="" extra="" white="" space,="" *="" strip="" octets.="" *="" *="" @since="" 2.9.0="" *="" *="" @param="" string="" $str="" *="" @return="" string="" */="" function="" sanitize_text_field(="" $str="" )="" {="" $filtered="wp_check_invalid_utf8(" $str="" );="" if="" (="" strpos($filtered,=""><') !="=" false="" )="" {="" $filtered="wp_pre_kses_less_than(" $filtered="" );="" this="" will="" strip="" extra="" whitespace="" for="" us.="" $filtered="wp_strip_all_tags(" $filtered,="" true="" );="" }="" else="" {="" $filtered="trim(" preg_replace('/[="" ]+/',="" '="" ',="" $filtered)="" );="" }="" $found="false;" while="" (="" preg_match('/%[a-f0-9]{2}/i',="" $filtered,="" $match)="" )="" {="" $filtered="str_replace($match[0]," '',="" $filtered);="" $found="true;" }="" if="" (="" $found="" )="" {="" strip="" out="" the="" whitespace="" that="" may="" now="" exist="" after="" removing="" the="" octets.="" $filtered="trim(" preg_replace('/="" +/',="" '="" ',="" $filtered)="" );="" }="" *="" *="" filter="" 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="" );="" }="">

sanitize_text_field() 源文件

相关