1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
<? function hex2rgb($hex){ if(! ereg("[0-9a-fA-F]{6}", $hex)) { echo "Error : input is not a valid hexadecimal number"; return 0; } for($i=0; $i<3; $i++) { $temp = substr($hex, 2*$i, 2); $rgb[$i] = 16 * hexdec(substr($temp, 0, 1)) + hexdec(substr($temp, 1, 1)); } return $rgb; } ?> |