- Trả về đúng định dạng mã màu
- Xoá ký tự # đầu tiên của mã màu
- Bạn có thể thêm funtion sau đây để chuyển mã màu từ hex sang rgb
function sanitize_rgb_color( $hex, $opacity ) {
$hex = sanitize_hex_color_no_hash ($hex);
if( strlen( $hex ) == 3) {
$r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) );
$g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) );
$b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) );
} else {
$r = hexdec( substr( $hex, 0, 2 ) );
$g = hexdec( substr( $hex, 2, 2 ) );
$b = hexdec( substr( $hex, 4, 2 ) );
}
return "rgba( $r, $g, $b, $opacity )";
}
Ví dụ: sanitize_rgb_color(#FFFFFF,0.9) => rgba( 255, 255, 255, 0.9 );
Chúc các bạn thành công 