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

$myRGB = array();
$myRGB = hex2rgb(#123ABC);

Server Side Code

//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){	//short form like #fff
		$R = substr($color, 1, 1).'0';
		$G = substr($color, 2, 1).'0';
		$B = substr($color, 3, 1).'0';	
	} else {		//long form like #FFFFFF
		$R = substr($color, 1, 2);
		$G = substr($color, 3, 2);
		$B = substr($color, 5, 2);
	}
 
	$red = hexdec($R);	//this is where the magic happens
	$green = hexdec($G);	//this is where the magic happens
	$blue = hexdec($B);	//this is where the magic happens	
 
	$rgb = array();
	$rgb['R']=$red;
	$rgb['G']=$green;
	$rgb['B']=$blue;
	return $rgb;
}

Candidate Code Suggestions

Add your suggestions and links here.