/** * 十六进制转RGB * * @param string $color 16进制颜色值 * @return array */ public static function hex2rgb($color) { $hexColor = str_replace('#', '', $color); $lens = strlen($hexColor); if ($lens != 3 && $lens != 6) { return false; } $newcolor = ''; if ($lens == 3) { for ($i = 0; $i < $lens; $i++) { $newcolor .= $hexColor[$i] . $hexColor[$i]; } } else { $newcolor = $hexColor; } $hex = str_split($newcolor, 2); $rgb = []; foreach ($hex as $key => $vls) { $rgb[] = hexdec($vls); } return $rgb; }
文章来源: PHP十六进制颜色转RGB颜色值