Jump to content

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

Edited by Manixat
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);
}

Edited by QuickOldCar
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.