Geekpedia Programming Tutorials






Convert RGB Color Value To Hexadecimal

A simple way to convert RGB colors to their hexadecimal values by using the dechex() function.

On Monday, October 6th 2008 at 09:09 AM
By Andrew Pociu (View Profile)
-----   (Rated 0 with 0 votes)
Contextual Ads
More PHP Resources
Advertisement
  1. function RGBToHex($RGBValues)
  2. {
  3.         $HexValue = "";
  4.         foreach ($RGBValues as $RGBValue)
  5.         {
  6.                 $HexValue .= (strlen(dechex($RGBValue)) == 1) ? '0' . dechex($RGBValue) : dechex($RGBValue);
  7.         }
  8.         return strtoupper($HexValue);
  9. }
  10.  
  11. // How to use the function to convert an RGB color to hex
  12. echo RGBToHex(array('R'=>255, 'G'=>202, 'B'=>91));
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this code snippet
Comment Current Comments
There are no comments.

Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs PHP Job Search
My skills include:

Enter a City:

Select a State:


Advanced Search >>
Latest Tech Bargains

Advertisement

Free Magazine Subscriptions

Today's Pictures

Today's Video

Other Resources

Latest Download

Latest Icons