1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
<? function rgb2hex($rgb){ if(!is_array($rgb)) { echo "Error : input must be an array"; return 0; } $hex = ""; for($i=0; $i<3; $i++) { if( ($rgb[$i] > 255) || ($rgb[$i] < 0) ) { echo "Error : input must be between 0 and 255"; return 0; } $tmp = dechex($rgb[$i]); if(strlen($tmp) < 2) $hex .= "0". $tmp; else $hex .= $tmp; } return $hex; } ?> |