diff --git a/rgba_to_hex.php b/rgba_to_hex.php new file mode 100644 index 0000000..f6507a2 --- /dev/null +++ b/rgba_to_hex.php @@ -0,0 +1,21 @@ +function convert_rgba_to_hex($string) { + $rgba = array(); + $hex = ''; + $regex = '#\((([^()]+|(?R))*)\)#'; + if (preg_match_all($regex, $string ,$matches)) { + $rgba = explode(',', implode(' ', $matches[1])); + } else { + $rgba = explode(',', $string); + } + + $rr = dechex($rgba['0']); + $gg = dechex($rgba['1']); + $bb = dechex($rgba['2']); + $aa = ''; + + if (array_key_exists('3', $rgba)) { + $aa = dechex($rgba['3'] * 255); + } + + return strtoupper("#$rr$gg$bb"); +}