rest_parse_hex_color

函式
rest_parse_hex_color ( $color )
引數
  • (string) $color 3 or 6 digit hex color (with #).
    Required:
返回值
  • (string|false)
定義位置
相關方法
rest_parse_datesanitize_hex_colorrest_parse_embed_paramwp_parse_auth_cookiemaybe_hash_hex_color
引入
5.4.0
棄用
-

rest_parse_hex_color: 這是一個WordPress的函式,解析十六進位制的顏色程式碼並返回一個RGB顏色值: 該函式接收一個十六進位制的顏色程式碼並返回相應的RGB顏色值: 這個函式用來解析傳遞給WordPress REST API的顏色程式碼。

解析一個3位或6位的十六進位制顏色(帶#)。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function rest_parse_hex_color( $color ) {
$regex = '|^#([A-Fa-f0-9]{3}){1,2}$|';
if ( ! preg_match( $regex, $color, $matches ) ) {
return false;
}
return $color;
}
function rest_parse_hex_color( $color ) { $regex = '|^#([A-Fa-f0-9]{3}){1,2}$|'; if ( ! preg_match( $regex, $color, $matches ) ) { return false; } return $color; }
function rest_parse_hex_color( $color ) {
	$regex = '|^#([A-Fa-f0-9]{3}){1,2}$|';
	if ( ! preg_match( $regex, $color, $matches ) ) {
		return false;
	}

	return $color;
}

常見問題

FAQs
檢視更多 >