src/Utilities/Colors/Color.php
public static function parse($color)
    {
        $lookupResult = ColorLookup::get($color);
        if (isset($lookupResult)) {
            return $lookupResult;
        }

        // pass on to dedicated functions depending on notation
        if (preg_match('/^#([0-9A-F]+)$/i', $color, $matches)) {
            list($r, $g, $b, $a) = self::parseHexComponents($matches[1]);
        } elseif (preg_match('/^rgba?\((.*)\)$/', $color, $matches)) {
            list($r, $g, $b, $a) = self::parseRGBAComponents($matches[1]);
        } elseif (preg_match('/^hsla?\((.*)\)$/', $color, $matches)) {
            list($r, $g, $b, $a) = self::parseHSLAComponents($matches[1]);
        }

        // any illegal component invalidates all components
        if (!isset($r) || !isset($g) || !isset($b) || !isset($a)) {
            return array(0, 0, 0, 0);
        }

        return self::clamp($r, $g, $b, $a);
    }
public static function parse($color)
    {
        $lookupResult = ColorLookup::get($color);
        if (isset($lookupResult)) {
            return $lookupResult;
        }

        // pass on to dedicated functions depending on notation
        if (preg_match('/^#([0-9A-F]+)$/i', $color, $matches)) {
            list($r, $g, $b, $a) = self::parseHexComponents($matches[1]);
        } elseif (preg_match('/^rgba?\((.*)\)$/', $color, $matches)) {
            list($r, $g, $b, $a) = self::parseRGBAComponents($matches[1]);
        } elseif (preg_match('/^hsla?\((.*)\)$/', $color, $matches)) {
            list($r, $g, $b, $a) = self::parseHSLAComponents($matches[1]);
        }

        // any illegal component invalidates all components
        if (!isset($r) || !isset($g) || !isset($b) || !isset($a)) {
            return array(0, 0, 0, 0);
        }

        return self::clamp($r, $g, $b, $a);
    }
public static function parse ( $ color ) { $ lookupResult = ColorLookup :: get ( $ color ) ; if ( isset ( $ lookupResult ) ) { return $ lookupResult ; } // pass on to dedicated functions depending on notation if ( preg_match ( '/^#([0-9A-F]+)$/i' , $ color , $ matches ) ) { list ( $ r , $ g , $ b , $ a ) = self :: parseHexComponents ( $ matches [ 1 ] ) ; } elseif ( preg_match ( '/^rgba?\((.*)\)$/' , $ color , $ matches ) ) { list ( $ r , $ g , $ b , $ a ) = self :: parseRGBAComponents ( $ matches [ 1 ] ) ; } elseif ( preg_match ( '/^hsla?\((.*)\)$/' , $ color , $ matches ) ) { list ( $ r , $ g , $ b , $ a ) = self :: parseHSLAComponents ( $ matches [ 1 ] ) ; } // any illegal component invalidates all components if ( ! isset ( $ r ) || ! isset ( $ g ) || ! isset ( $ b ) || ! isset ( $ a ) ) { return array ( 0 , 0 , 0 , 0 ) ; } return self :: clamp ( $ r , $ g , $ b , $ a ) ; }
Converts any valid SVG color string into an array of RGBA components.

All of the components are ints 0-255.

@param string $color The color string to convert, as specified in SVG.

@return int[] The color converted to RGBA components.
Converts any valid SVG color string into an array of RGBA components .