Jump to content

Numeric To Hexadecimal


Manixat

Recommended Posts

Hello freaks,

 

I'm trying to create a timer that changes color depending on the time remaining. The easiest thing I thought I could do is have if statements but that would not lead to a smooth change in colors, so I figured I have to calculate the color, which led to the problem. How do I turn numeric values to hexadecimal color code ?

 

More accurately - I need to have #00FF00 if the timer is equal to 60*60*24*31 or greater and run down to #FF0000?

 

Any help is appreciated,

 

Manix

Link to comment
https://forums.phpfreaks.com/topic/271298-numeric-to-hexadecimal/
Share on other sites

In case want rgb

 

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);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.