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. Link to comment https://forums.phpfreaks.com/topic/116495-convert-decimal-to-html-hex/ Share on other sites More sharing options...
ronnie88 Posted July 24, 2008 Share Posted July 24, 2008 http://php.net/urlencode Link to comment https://forums.phpfreaks.com/topic/116495-convert-decimal-to-html-hex/#findComment-599048 Share on other sites More sharing options...
ronnie88 Posted July 24, 2008 Share Posted July 24, 2008 http://us2.php.net/dechex Link to comment https://forums.phpfreaks.com/topic/116495-convert-decimal-to-html-hex/#findComment-599054 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) Link to comment https://forums.phpfreaks.com/topic/116495-convert-decimal-to-html-hex/#findComment-599063 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.