Originally posted by VooDooRT
All I keep getitng with that is 000000 when I want to covert #000000 to 0,0,0 or #f5f5f5 to the 00,00,00 equivalent.
i'm not sure what you are doing wrong but if you call my function with:
$rgb_value = hexTOrgb('f5f5f5');
you have in $rgb_value => 245245245
if you want to have them seperated with any character, use this function:
<?php
// function converts hex to rgb values
// argument $hex may be #xxxxxx OR xxxxxx BUT must be 6 length
// argument $sep may be any character ( e.g. , OR ; )
function hexTOrgb($hex, $sep = '') {
$rgb = str_replace('#', '', $hex);
if (strlen($rgb) == 6) {
$r = hexdec($rgb{0} . $rgb{1});
$g = hexdec($rgb{2} . $rgb{3});
$b = hexdec($rgb{4} . $rgb{5});
return $r . $sep . $g . $sep . $b;
} else {
return '00' . $sep . '00' . $sep . '00';
}
}
$rgb_value = hexTOrgb('#0A141E');
echo "<pre>'#0A141E' ==> $rgb_value</pre>";
$rgb_value = hexTOrgb('#F5F5F5', ',');
echo "<pre>'#F5F5F5', ',' ==> $rgb_value</pre>";
?>
ceeyaa.MeX