- 
      
- 
        Save INDIAN2020/6b89049ffc21cbeec8a5cf97f7a6ebc1 to your computer and use it in GitHub Desktop. 
    Convert hex colors to rgb colors.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| function hex2rgb($hex, $return_as_array = 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)); | |
| } | |
| $rgb = array($r, $g, $b); | |
| if( !$return_as_array ) | |
| return implode(",", $rgb); // returns the rgb values separated by commas | |
| else | |
| return $rgb; // returns an array with the rgb values | |
| } | |
| ?> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment