Style Color... how to convert rgb() to hex

Mr. Goodie2Shoes

Well-known member
Well, the title says it all, I am calling @primaryMedium which needs to be in HEX format... but it's giving me in rgb(x, y, z) format...

Thanks! :)
 

Chris D

XenForo developer
Staff member
You might have to write a custom class for this...

There are some colour related helpers but the end result is always RGB or RGBA.

This one may help:

Rich (BB code):
function rgb2hex($rgb)
{
$hex = "#";​
$hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);​
$hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);​
$hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);​
return $hex; // returns the hex value including the number sign (#)​
}
 

Mr. Goodie2Shoes

Well-known member
oh... forgot to mention, the input is actually an array... so you have to separate them by
PHP:
$rgb = str_replace(' ', '', $rgb) //just to make sure...
$rgb = explode(',', $rgb);
 
Top