Voting

: three minus one?
(Example: nine)

The Note You're Voting On

Zigbigidorlu at hotmail dot com
19 years ago
Here's a very simple and very effective code to change a HEX color to RGB.

<?php
function HEX2RGB($color){
$color_array = array();
$hex_color = strtoupper($color);
for(
$i = 0; $i < 6; $i++){
$hex = substr($hex_color,$i,1);
switch(
$hex){
case
"A": $num = 10; break;
case
"B": $num = 11; break;
case
"C": $num = 12; break;
case
"D": $num = 13; break;
case
"E": $num = 14; break;
case
"F": $num = 15; break;
default:
$num = $hex; break;
}
array_push($color_array,$num);
}
$R = (($color_array[0] * 16) + $color_array[1]);
$G = (($color_array[2] * 16) + $color_array[3]);
$B = (($color_array[4] * 16) + $color_array[5]);
return array(
$R,$G,$B);
unset(
$color_array,$hex,$R,$G,$B);
}
?>

<< Back to user notes page

To Top