David Bélanger
David Bélanger

Reputation: 7438

PHP ARGB to Alpha-Hex and Alpha-Hex to ARGB

I got the following color -16777216 and I want to convert it to a alpha-hex code like this 00FFBBCC in PHP. I also want to be able to do the reverse. I really don't know where to start and my friend Google has no answer for me.

Any one can help please ?

Thank you.

Upvotes: -1

Views: 704

Answers (1)

Dodo
Dodo

Reputation: 131

What about using dechex()?

echo dechex(-16777216);

It outputs ff000000

If you want uppercase letters, simply use strtoupper():

echo strtoupper(dechex(-16777216)); //FF000000

Edit: to do the reverse, use hexdec() instead of dechex()

Upvotes: 1

Related Questions