Forum Moderators: coopster

Message Too Old, No Replies

RGB Colors to #XXXXXX with PHP?

         

globay

2:54 am on Feb 9, 2003 (gmt 0)

10+ Year Member



I want to use a color which is

Red: 100
Blue: 100
Yellow: 100
(#646464)

How could I convert this to HTML colors( by using PHP)?

--
globay

jatar_k

9:33 am on Feb 9, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



$colour = "646464";
echo "#" . $colour or <?= $colour?>

is this what you mean?

globay

12:11 pm on Feb 9, 2003 (gmt 0)

10+ Year Member



No, I meant something different:

Red: 50 -> 32 (Hexadecimal)
Green: 100 -> 64
Blue: 200 -> C8

-> #3264C8

Basically it is how to transform 100 (dezimal) to 100 (Hexadecimal).

--
thanks;
globay

---------
<Added> Just found the solution! dechex( )</added>

Nick_W

12:16 pm on Feb 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$hex=dechex($dec); [php.net]

Nick

andreasfriedrich

12:49 pm on Feb 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use either dechex() [php.net] to convert each decimal number to its hexadecimal representation or use sprintf() [php.net] to get the color string like this:


$color = sprintf("#%x%x%x", 100, 100, 100);

$color will contain the string #646464

Andreas

globay

1:54 pm on Feb 9, 2003 (gmt 0)

10+ Year Member



thanks,

sprintf() will make it even easier!

jatar_k

7:27 pm on Feb 9, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



sorry globay, I had no idea what you meant.

Those functions are the way to go.