16进制的颜色值是从#000000到#FFFFFF,而RBG颜色颜色值是由三组0到255之间的数字组成。十六进制颜色值转RGB颜色值,只需要将十六进制颜色值 # 号后面的每两个值一组转成对应的十进制即可,代码如下:
function hex2rgba($hexColor='#000') { $color = str_replace('#','',strtoupper(trim($hexColor))); if(strlen($color)>3){ $rgba=array( 'r'=>hexdec(substr($color,0,2)), 'g'=>hexdec(substr($color,2,2)), 'b'=>hexdec(substr($color,4,2)), 'a'=>0 ); }else{ $rgba=array( 'r'=>hexdec(substr($color,0,1). substr($color,0,1)), 'g'=>hexdec(substr($color,1,1). substr($color,1,1)), 'b'=>hexdec(substr($color,2,1). substr($color,2,1)), 'a'=>0 ); } return $rgba; }
调用:
print_r(hex2rgba('#f00'))
或
print_r(hex2rgba('#ff0000'))
上一篇:TP6下微信支付wechatpay-apiv3之wechatpay-php使用,包括下单、支付、查询、关闭
下一篇:PHP+Mysql原生随机查询语句及TP6随机查询数据
讨论数量:0