WordPress函数:sanitize_hex_color 移除 hex color 中的异常字符

江河/ 01月21日/ WordPress/ 浏览 386

函数原型:


sanitize_hex_color( string $color ): string|void


移除 hex color 中的异常字符。返回“、3位或6位十六进制颜色(带#)或不返回任何值。有关清除不带#的值的信息,请参阅sance_hex_color_no_hash()。


参数说明:


$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;
	}
}


使用举例:


sanitize_hex_color('#FFF-FFF')


发表评论

暂无评论,抢个沙发...

客服 工单