Copy CodeThe code is as follows:
Echo Implode (",", Hextorgb ("#F7F7DA")). "
";
echo Rgbtohex ("RGB (247,247,218)")?>
function Hextorgb ($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],
$colour [2]. $colour [2]
);
} else {
return false;
}
$r = Hexdec ($r);
$g = Hexdec ($g);
$b = Hexdec ($b);
Return Array (
' Red ' = $r,
' Green ' = $g,
' Blue ' = $b
);
}
function Rgbtohex ($RGB) {
$regexp = "/^rgb\ ([0-9]{0,3}) \,\s* ([0-9]{0,3}) \,\s* ([0-9]{0,3}) \)/";
$re = Preg_match ($regexp, $rgb, $match);
$re = Array_shift ($match);
$hexColor = "#";
$hex = Array (
' 0 ',
' 1 ',
' 2 ',
' 3 ',
' 4 ',
' 5 ',
' 6 ',
' 7 ',
' 8 ',
' 9 ',
' A ',
' B ',
' C ',
' D ',
' E ',
F
);
for ($i = 0; $i < 3; $i + +) {
$r = null;
$c = $match [$i];
$hexAr = Array ();
while ($c > 16) {
$r = $c% 16;
$c = ($c/16) >> 0;
Array_push ($hexAr, $hex [$r]);
}
Array_push ($hexAr, $hex [$c]);
$ret = Array_reverse ($hexAr);
$item = Implode (' ', $ret);
$item = Str_pad ($item, 2, ' 0 ', str_pad_left);
$hexColor. = $item;
}
return $hexColor;
}
?>
http://www.bkjia.com/PHPjc/326971.html www.bkjia.com true http://www.bkjia.com/PHPjc/326971.html techarticle Copy the code as follows:? PHP Echo Implode (",", Hextorgb ("#F7F7DA")). "br/"; echo Rgbtohex ("RGB (247,247,218)")?? PHP function Hextorgb ($colour) {if ($colour [0] = = ' # ' ...