public function hex2rgb($hex, $returnString = FALSE)
    {
        $hex = str_replace('#', '', $hex);

        if(strlen($hex) == 3)
        {
            $r = hexdec(substr($hex,0,1).substr($hex,0,1));
            $g = hexdec(substr($hex,1,1).substr($hex,1,1));
            $b = hexdec(substr($hex,2,1).substr($hex,2,1));
        }
        else
        {
            $r = hexdec(substr($hex,0,2));
            $g = hexdec(substr($hex,2,2));
            $b = hexdec(substr($hex,4,2));
        }

        if($returnString)
        {
            return implode(', ', array($r, $g, $b));
        }

        return array($r, $g, $b);
    }
public function hex2rgb($hex, $returnString = FALSE)
    {
        $hex = str_replace('#', '', $hex);

        if(strlen($hex) == 3)
        {
            $r = hexdec(substr($hex,0,1).substr($hex,0,1));
            $g = hexdec(substr($hex,1,1).substr($hex,1,1));
            $b = hexdec(substr($hex,2,1).substr($hex,2,1));
        }
        else
        {
            $r = hexdec(substr($hex,0,2));
            $g = hexdec(substr($hex,2,2));
            $b = hexdec(substr($hex,4,2));
        }

        if($returnString)
        {
            return implode(', ', array($r, $g, $b));
        }

        return array($r, $g, $b);
    }
public function hex2rgb ( $ hex , $ returnString = FALSE ) { $ hex = str_replace ( '#' , '' , $ hex ) ; if ( strlen ( $ hex ) == 3 ) { $ r = hexdec ( substr ( $ hex , 0 , 1 ) . substr ( $ hex , 0 , 1 ) ) ; $ g = hexdec ( substr ( $ hex , 1 , 1 ) . substr ( $ hex , 1 , 1 ) ) ; $ b = hexdec ( substr ( $ hex , 2 , 1 ) . substr ( $ hex , 2 , 1 ) ) ; } else { $ r = hexdec ( substr ( $ hex , 0 , 2 ) ) ; $ g = hexdec ( substr ( $ hex , 2 , 2 ) ) ; $ b = hexdec ( substr ( $ hex , 4 , 2 ) ) ; } if ( $ returnString ) { return implode ( ', ' , array ( $ r , $ g , $ b ) ) ; } return array ( $ r , $ g , $ b ) ; }
Hexadecimal color to RGB conversion
@param string $hex color
@param bool $returnString
@return array|string
Hexadecimal color to RGB conversion