经测试代码如下:
/**
* 把一个HEX格式(如:#FF00FF)的颜色代码转换成RGB格式的颜色代码
*
* @param
* @arrange (512.笔记) jb51.cc
**/
function Hex2RGB($color){
$color = str_replace('#','',$color);
if (strlen($color) != 6){ return array(0,0); }
$rgb = array();
for ($x=0;$x<3;$x++){
$rgb[$x] = hexdec(substr($color,(2*$x),2));
}
return $rgb;
}
// Example usage:
print_r(Hex2RGB('#B3DAF5'));
/*
Returns an array (R,G,B):
Array
(
[0] => 179
[1] => 218
[2] => 245
)
*/
// Another cool way to define RGB colors with
// Hex values: (like #B3DAF5)
$rgb = array(0xB3,0xDA,0xF5);
print_r($rgb);
/* output:
Array
(
[0] => 179
[1] => 218
[2] => 245
)
*/
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/528943.html