I'm making a hit counter service, I want users to be able input hex colors, but then convert that to rgb values when the script is run. How would i do that?
I made this function for my scripts. You can use it <?php $color = '#FF00CC'; $new_color = getRGBCode($color); print_r($new_color); function getRGBCode($s) { $rgbArr = array(); $s = str_replace('#','',$s); if (6 == strlen($s)) { $rgbArr[] = hexdec(substr($s, 0, 2)); $rgbArr[] = hexdec(substr($s, 2, 2)); $rgbArr[] = hexdec(substr($s, 4, 2)); } return $rgbArr; } ?> PHP:
$int = hexdec(str_replace('#', '', $hex)); $r = $int >> 16 & 255; $g = $int >> 8 & 255 $b = $int & 255; Code (markup):