iwarlord Posted July 24, 2008 Share Posted July 24, 2008 Hello. I hope someone here can help. Basically I want to convert a truecolor number to html hex. This javascript function does it: function decimalColorToHTMLcolor(number) { var intnumber = number - 0; var red, green, blue; var template = "#000000"; red = (intnumber&0x0000ff) << 16; green = intnumber&0x00ff00; blue = (intnumber&0xff0000) >>> 16; intnumber = red|green|blue; var HTMLcolor = intnumber.toString(16); HTMLcolor = template.substring(0,7 - HTMLcolor.length) + HTMLcolor; return HTMLcolor; } But I need a PHP version and I don't know where to begin. Any suggestions? Thanks. Quote Link to comment Share on other sites More sharing options...
ronnie88 Posted July 24, 2008 Share Posted July 24, 2008 http://php.net/urlencode Quote Link to comment Share on other sites More sharing options...
ronnie88 Posted July 24, 2008 Share Posted July 24, 2008 http://us2.php.net/dechex Quote Link to comment Share on other sites More sharing options...
Barand Posted July 24, 2008 Share Posted July 24, 2008 do you mean <?php $decColor = 16776960; $HTMLcolor = sprintf ('#%06X', $decColor); echo $HTMLcolor; // #FFFF00 ?> (If $decColor is 255, dechex only gives FF, not 0000FF) Quote Link to comment 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.