I googled about a function how to convert hex to rgb color code
<?php
function html2rgb($color)
{
if ($color[0] == '#')
$color = substr($color, 1);
if (strlen($color) == 6)
list($r, $g, $b) = array($color[0].$color[1],
$color[2].$color[3],
$color[4].$color[5]);
elseif (strlen($color) == 3)
list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
else
return false;
$r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
return array($r, $g, $b);
}
?>
I can't access the data like this echo html2rgb('#cccccc'); because it's an array
// Edit I just want to say thanks to the guys how answered. :)
well you can access it like this:
$rgb = html2rgb('#cccccc');
$r = $rgb[0];
$g = $rgb[1];
$b = $rgb[2];
and then
echo "Red = $r, Green = $g, Blue = $b";
or just var_dump($rgb)
or print_r($rgb)
try print_r(html2rgb('#cccccc'));
This should help you understand: What's the difference between echo, print, and print_r in PHP?
I guess you'd want something more along the lines of:
$cc = html2rgb('#cccccc');
echo "[".$cc[0].",".$cc[1].",".$cc[2]."]";