Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
computers:php_hex2rbg_color_scheme [2009/07/14 05:12]
daniel
computers:php_hex2rbg_color_scheme [2015/03/24 05:42] (current)
Line 7: Line 7:
  
 <code php> ​ <code php> ​
-$myRBG = array(); +$myRGB = array(); 
-$myRBG hex2rbg(#123ABC);+$myRGB hex2rgb(#123ABC);
 </​code>​ </​code>​
  
Line 18: Line 18:
 //a hex html code (e.g. #3FE5AA) //a hex html code (e.g. #3FE5AA)
 function hex2rgb ($color = "#​000000"​){ function hex2rgb ($color = "#​000000"​){
- if(strlen($color)<​5){+ if(strlen($color)<​5){ //short form like #fff
  $R = substr($color,​ 1, 1).'​0';​  $R = substr($color,​ 1, 1).'​0';​
  $G = substr($color,​ 2, 1).'​0';​  $G = substr($color,​ 2, 1).'​0';​
  $B = substr($color,​ 3, 1).'​0';​   $B = substr($color,​ 3, 1).'​0';​
- } else {+ } else { //long form like #FFFFFF
  $R = substr($color,​ 1, 2);  $R = substr($color,​ 1, 2);
  $G = substr($color,​ 3, 2);  $G = substr($color,​ 3, 2);
  $B = substr($color,​ 5, 2);  $B = substr($color,​ 5, 2);
  }  }
- $red = hexdec($R);​ + 
- $green = hexdec($G);​ + $red = hexdec($R);​ //this is where the magic happens 
- $blue = hexdec($B);+ $green = hexdec($G);​ //this is where the magic happens 
 + $blue = hexdec($B);​ //this is where the magic happens  
  $rgb = array();  $rgb = array();
  $rgb['​R'​]=$red;​  $rgb['​R'​]=$red;​