Manixat Posted November 28, 2012 Share Posted November 28, 2012 (edited) 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 November 28, 2012 by Manixat Quote Link to comment https://forums.phpfreaks.com/topic/271298-numeric-to-hexadecimal/ Share on other sites More sharing options...
Muddy_Funster Posted November 28, 2012 Share Posted November 28, 2012 dechex() Quote Link to comment https://forums.phpfreaks.com/topic/271298-numeric-to-hexadecimal/#findComment-1395915 Share on other sites More sharing options...
QuickOldCar Posted November 28, 2012 Share Posted November 28, 2012 (edited) 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 November 28, 2012 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/271298-numeric-to-hexadecimal/#findComment-1395916 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.