Differences

This shows you the differences between two versions of the page.

Link to this comparison view

computers:php_hex2rbg_color_scheme [2009/07/14 05:12]
daniel
computers:php_hex2rbg_color_scheme [2015/03/24 05:42]
Line 1: Line 1:
-====== php hex2rbg color scheme ====== 
  
-Turn a hex color scheme to RBG color scheme. ​ You can also easily do the reverse by studying the code. 
- 
- 
-==== Usage Example ==== 
- 
-<code php> ​ 
-$myRBG = array(); 
-$myRBG = hex2rbg(#​123ABC);​ 
-</​code>​ 
- 
-==== Server Side Code  ==== 
- 
-<code php> 
-//function hex2dec 
-//returns an associative array (keys: R, G, B) from 
-//a hex html code (e.g. #3FE5AA) 
-function hex2rgb ($color = "#​000000"​){ 
- if(strlen($color)<​5){ 
- $R = substr($color,​ 1, 1).'​0';​ 
- $G = substr($color,​ 2, 1).'​0';​ 
- $B = substr($color,​ 3, 1).'​0';​  
- } else { 
- $R = substr($color,​ 1, 2); 
- $G = substr($color,​ 3, 2); 
- $B = substr($color,​ 5, 2); 
- } 
- $red = hexdec($R); 
- $green = hexdec($G); 
- $blue = hexdec($B); 
- $rgb = array(); 
- $rgb['​R'​]=$red;​ 
- $rgb['​G'​]=$green;​ 
- $rgb['​B'​]=$blue;​ 
- return $rgb; 
-} 
- 
-</​code>​ 
- 
- 
- 
-====== Candidate Code Suggestions ====== 
-Add your suggestions and links here.