onetone_hex2rgb

Convert Hex Code to RGB.

Description

(array) onetone_hex2rgb( (string) $hex ); 

Returns (array)

RGB values

Parameters (1)

0. $hex (string)
Color Hex Code

Usage

  1. if ( !function_exists( 'onetone_hex2rgb' ) ) { 
  2. require_once '/includes/theme-functions.php'; 
  3.  
  4. // Color Hex Code 
  5. $hex = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = onetone_hex2rgb($hex); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/theme-functions.php  
  1. function onetone_hex2rgb( $hex ) { 
  2. if ( strpos( $hex, 'rgb' ) !== FALSE ) { 
  3.  
  4. $rgb_part = strstr( $hex, '(' ); 
  5. $rgb_part = trim($rgb_part, '(' ); 
  6. $rgb_part = rtrim($rgb_part, ')' ); 
  7. $rgb_part = explode( ', ', $rgb_part ); 
  8.  
  9. $rgb = array($rgb_part[0], $rgb_part[1], $rgb_part[2], $rgb_part[3]); 
  10.  
  11. } elseif( $hex == 'transparent' ) { 
  12. $rgb = array( '255', '255', '255', '0' ); 
  13. } else { 
  14.  
  15. $hex = str_replace( '#', '', $hex ); 
  16.  
  17.  
  18. if( strlen( $hex ) == 3 ) { 
  19. $r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) ); 
  20. $g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) ); 
  21. $b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) ); 
  22. } else { 
  23. $r = hexdec( substr( $hex, 0, 2 ) ); 
  24. $g = hexdec( substr( $hex, 2, 2 ) ); 
  25. $b = hexdec( substr( $hex, 4, 2 ) ); 
  26. $rgb = array( $r, $g, $b ); 
  27.  
  28. return $rgb; // returns an array with the rgb values