This article describes the PHP implementation of the color hex value converted to RGB method. Share to everyone for your reference, specific as follows:
function Hex2rgb ($colour) {
if ($colour [0] = = ' # ') {
$colour = substr ($colour, 1);
}
if (strlen ($colour) = = 6) {
list ($r, $g, $b) = Array ($colour [0]. $colour [1], $colour [2]. $colour [3], $colour [ 4]. $colour [5]);
} ElseIf (strlen ($colour) = = 3) {
list ($r, $g, $b) = Array ($colour [0]. $colour [0], $colour [1]. $colour [1], $col OUR[2]. $colour [2]);
} else {return
false;
}
$r = Hexdec ($r);
$g = Hexdec ($g);
$b = Hexdec ($b);
Return array (' Red ' => $r, ' green ' => $g, ' Blue ' => $b);
}
Test
Var_dump (Hex2rgb ("#eeeeee"));
The results of the operation are as follows:
Array (3) {
["red"]=>
int (238)
["Green"]=>
int (238)
["Blue"]=>
int (238)
}
About color value conversion and acquisition can also refer to the site online tools:
RGB Color Coding Generator
Online Web Color tool
RGB Color Query Matrix _ color code Table _ color of the English name Daquan
For more information about PHP interested readers can view the site topics: "PHP array" operation Skills Encyclopedia, "PHP Mathematical Calculation Skills Summary", "PHP graphics and pictures Operating skills summary", "PHP operation Office Document Skills Summary (including Word,excel, Access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.