sanitize_hex_color

函式
sanitize_hex_color ( $color )
引數
  • (string) $color
    Required:
返回值
  • (string|void)
定義位置
相關方法
sanitize_hex_color_no_hashsanitize_usersanitize_termsanitize_text_fieldsanitize_html_class
引入
3.4.0
棄用
-

sanitize_hex_color: 這是一個WordPress的函式,可以對十六進位制的顏色程式碼進行淨化。它用於驗證和淨化顏色程式碼以防止錯誤: 這個函式有一個引數,就是要淨化的顏色程式碼。

淨化一個十六進位制顏色。

返回”、3位或6位的十六進位制顏色(帶#),或者什麼都沒有。要對沒有#的值進行淨化,請看sanitize_hex_color_no_hash()。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function sanitize_hex_color( $color ) {
if ( '' === $color ) {
return '';
}
// 3 or 6 hex digits, or the empty string.
if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
return $color;
}
}
function sanitize_hex_color( $color ) { if ( '' === $color ) { return ''; } // 3 or 6 hex digits, or the empty string. if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) { return $color; } }
function sanitize_hex_color( $color ) {
	if ( '' === $color ) {
		return '';
	}

	// 3 or 6 hex digits, or the empty string.
	if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
		return $color;
	}
}

常見問題

FAQs
檢視更多 >