/** * @param string $hex #FF0000 oder FF0000 * @param array $default * @return array */ public static function hex2rgb(string $hex, array $default = ['r' => 0, 'g' => 0, 'b' => 0]) : array { if (substr($hex, 0, 1) !== '#') $hex = '#'.$hex; if (!preg_match('/#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\b/', $hex)) return $default; $r = substr($hex, 1, 2); $r = hexdec($r); $g = substr($hex, 3, 2); $g = hexdec($g); $b = substr($hex, 5, 2); $b = hexdec($b); return [ 'r' => $r, 'g' => $g, 'b' => $b ]; }