Jump to content

php function to convert "FF" to "255"?


michaellunsford

Recommended Posts

I'm wanting to convert a web color, like FF0000 to an RGB value, 255,0,0. I was going to substr the web color and make my own math function. Before I do all that, is there a built-in function that does this already? Or something close?

Thanks!
Link to comment
https://forums.phpfreaks.com/topic/34931-php-function-to-convert-ff-to-255/
Share on other sites

[url=http://uk2.php.net/hex2dec]hex2dec[/url] should set you on your way ;)
you'll just have to note that each pair in the 6 character hex string amounts to a number, so you will (as far as i know, unless there's another specific function) have to split it up first into 3 parts and then perform the hex2dec conversions. the user notes on the php manual hex2dec page does bring up the subject of converting colours though.

cheers
[quote author=redbullmarky link=topic=123189.msg508862#msg508862 date=1169247668]
[url=http://uk2.php.net/hex2dec]hex2dec[/url] should set you on your way ;)
you'll just have to note that each pair in the 6 character hex string amounts to a number, so you will (as far as i know, unless there's another specific function) have to split it up first into 3 parts and then perform the hex2dec conversions.

cheers
[/quote]
In fact, most of the comments on that page deal with this topic.
[quote author=michaellunsford link=topic=123189.msg508870#msg508870 date=1169248324]
Thanks for the quick replies. I checked the manual and did a google search -- but I didn't know the right language.

bin2hex looks like the magic. Thanks!
[/quote]

you mean hex2dec? ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.