sanitize_text_field

函式
sanitize_text_field ( $str )
引數
  • (string) $str String to sanitize.
    Required:
返回值
  • (string) Sanitized string.
相關
  • sanitize_textarea_field()
  • wp_check_invalid_utf8()
  • wp_strip_all_tags()
定義位置
相關方法
_sanitize_text_fieldssanitize_textarea_fieldsanitize_term_fieldsanitize_user_fieldsanitize_post_field
引入
2.9.0
棄用
-

sanitize_text_field: 這是一個WordPress的函式,它對單行文字進行淨化處理。它用於刪除任何HTML標籤和轉義任何特殊字元以防止XSS攻擊: 這個函式有一個引數,就是要處理的文字。

從使用者輸入或資料庫中對一個字串進行淨化。

– 檢查是否有無效的UTF-8。
– 將單個`<`字元轉換為實體
– 剝離所有標籤
– 移除換行符、製表符和額外的空白處
– 剝離八位數

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >