Function to convert an hexadecimal to rgb value
Friday, February 16th, 2007Params:$hex: Hexadecimal value
Return:Array with the decimal value for red, gren and blue.
function hexToRgb($hex)
-
{
-
//Delete the # char (if exist)
-
if (0 === strpos($hex, '#')) {
-
$hex = substr($hex, 1);
-
} else if (0 === strpos($hex, '&H')) {
-
$hex = substr($hex, 2);
-
}
-
//get the 3 hex values
-
$cutpoint = ceil(strlen($hex) / 2)-1;
-
$rgb = explode(':', wordwrap($hex, $cutpoint, ':', $cutpoint), 3);
-
-
//Convert to decimal
-
$rgb[0] = (isset($rgb[0]) ? hexdec($rgb[0]) : 0);
-
$rgb[1] = (isset($rgb[1]) ? hexdec($rgb[1]) : 0);
-
$rgb[2] = (isset($rgb[2]) ? hexdec($rgb[2]) : 0);
-
-
return $rgb;
-
}
Posted in Functions, Php | No Comments »

