public function hexToRgb( $hex ) {
        $hex = ltrim($hex, '#'); // Remove #

        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));
        }
        return array($r, $g, $b); // Returns an array with the rgb values
    }
public function hexToRgb( $hex ) {
        $hex = ltrim($hex, '#'); // Remove #

        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));
        }
        return array($r, $g, $b); // Returns an array with the rgb values
    }
public function hexToRgb ( $ hex ) { $ hex = ltrim ( $ hex , '#' ) ; // Remove # 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 ) ) ; } return array ( $ r , $ g , $ b ) ; // Returns an array with the rgb values }
Convert hex string to RGB
@param string $hex Hex string. Possible values: #ffffff, #fff, fff
@return array Contains (RGB) values red, green and blue
Convert hex string to RGB