Converts a hex color to rgb tuples

@return mixed
@param string $hex
@param bool $asString
972613
protected function hex2rgb ($hex, $asString = false) 
	{
        // strip off any leading #
        if (0 === strpos($hex, '#')) 
		{
           $hex = substr($hex, 1);
        } 
		elseif (0 === strpos($hex, '&H')) 
		{
           $hex = substr($hex, 2);
        }

        // break into hex 3-tuple
        $cutpoint = ceil(strlen($hex) / 2)-1;
        $rgb = explode(':', wordwrap($hex, $cutpoint, ':', $cutpoint), 3);

        // convert each tuple to decimal
        $rgb[0] = (isset($rgb[0]) ? hexdec($rgb[0]) : 0);
        $rgb[1] = (isset($rgb[1]) ? hexdec($rgb[1]) : 0);
        $rgb[2] = (isset($rgb[2]) ? hexdec($rgb[2]) : 0);

        return ($asString ? "{$rgb[0]} {$rgb[1]} {$rgb[2]}" : $rgb);
    }
473513
private function _hexToAscii($hexString){
        $bytes = str_split($hexString, 2);
        $string = '';
        foreach($bytes as $byte){
            $string .= chr(hexdec($byte)); // convert hex to dec to ascii character. See http://www.ascii.cl/
        }
        return $string;
    }
98303
public static function ToHexStringArray ($rgb) {
		$rgb = trim($rgb, '#');
		if ($rgb === '' || ($range = strlen($rgb) / 3) > 2) {
			return false;
		}

		$hex_array = [substr($rgb, 0, $range), substr($rgb, 1 * $range, $range), substr($rgb, 2 * $range, $range)];
		if ($range === 1) {
			$hex_array[0] .= $hex_array[0];
			$hex_array[1] .= $hex_array[1];
			$hex_array[2] .= $hex_array[2];
		}

		return $hex_array;
	}
926798
public static function hex2rgb($hex)
    {
        $hex = str_replace("#", "", $hex);
        $r = hexdec(substr($hex,0,2));
        $g = hexdec(substr($hex,2,2));
        $b = hexdec(substr($hex,4,2));
        return "$r,$g,$b";
    }
1204225
function rgbaToHex(color) {
    color = color.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);

    var hex = (color && color.length === 4) ? "#" +
    ("0" + parseInt(color[1],10).toString(16)).slice(-2) +
    ("0" + parseInt(color[2],10).toString(16)).slice(-2) +
    ("0" + parseInt(color[3],10).toString(16)).slice(-2) : '';

    return hex.toUpperCase();
  }
382602
public function rgb($str) {
        $hsl = $this->hsl($str);
        return $this->HSL2RGB($hsl[0], $hsl[1], $hsl[2]);
    }
384604
def hexstr(x, onlyasc=0, onlyhex=0, color=False):
    """"""
    x = bytes_encode(x)
    _sane_func = sane_color if color else sane
    s = []
    if not onlyasc:
        s.append(" ".join("%02X" % orb(b) for b in x))
    if not onlyhex:
        s.append(_sane_func(x))
    return "  ".join(s)
200259
public static function validateHexColorString(string $hex) : bool
    {
        // optional leading hash #
        $length = strlen( ltrim($hex, '#') );

        // must be 3 or 6 characters
        switch ($length) {
            case 3: break;
            case 6: break;
            default: return false;
        }

        return preg_match('/^#?[0-9a-fA-F]{3,6}$/', $hex) === 1;
    }
83398
def rgb_to_hex(color):
    
    rgb = eval(color.replace('rgb', ''))
    # return '#'+''.join(map(chr, rgb)).encode('hex')
    return '#' + ''.join(['{0:02x}'.format(x).upper() for x in rgb])
296516
def _rgb_to_hex(rgbs):
    """"""
    rgbs, n_dim = _check_color_dim(rgbs)
    return np.array(['#%02x%02x%02x' % tuple((255*rgb[:3]).astype(np.uint8))
                     for rgb in rgbs], '|U7')
160807
public function getArguments($asString = false)
    {
        if ($asString) {
            $str = (string) $this->arguments;
            return $str;
        }
        return $this->arguments->all();
    }
1329770
public static function rgb2Hex($rgb)
    {
        $regexp = "/^rgb\(([0-9]{0,3})\,\s*([0-9]{0,3})\,\s*([0-9]{0,3})\)/";
        $re = preg_match($regexp, $rgb, $match);
        $re = array_shift($match);
        $hexColor = "#";
        $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
        for ($i = 0; $i < 3; $i++) {
            $r = null;
            $c = $match[$i];
            $hexAr = array();
            while ($c > 16) {
                $r = $c % 16;
                $c = ($c / 16) >> 0;
                array_push($hexAr, $hex[$r]);
            }
            array_push($hexAr, $hex[$c]);
            $ret = array_reverse($hexAr);
            $item = implode('', $ret);
            $item = str_pad($item, 2, '0', STR_PAD_LEFT);
            $hexColor .= $item;
        }
        return $hexColor;
    }
448140
public static function fromHexString(string $string) : Colour
    {
        list($r, $g, $b) = ColourStringParser::parseHexString($string);

        return new self($r, $g, $b);
    }
329782
public static function formatRequestData($asString = true)
    {
        $fromServer = array(
            'REQUEST_URI',
            'REQUEST_METHOD',
            'HTTP_REFERER',
            'QUERY_STRING',
            'HTTP_USER_AGENT',
            'REMOTE_ADDR',
        );

        if($asString) {
            $s = "\n\n";
            $s .= isset($_REQUEST)? "REQUEST: " . print_r($_REQUEST, true) . PHP_EOL   : '';
            foreach ($fromServer as $item) {
                $s .= isset($_SERVER[$item]) ? "{$item}: {$_SERVER[$item]}\n" : '';
            }
        } else {
            $s = array(
                'REQUEST' => $_REQUEST,
                'SERVER'  => $_SERVER,
            );
        }

        return $s;
    }
63475
static function FromArgbHex($hex)
    {
        $cleanHex = ltrim($hex, '#');
        $a = hexdec(substr($cleanHex, 0, 2));
        $r = hexdec(substr($cleanHex, 2, 2));
        $g = hexdec(substr($cleanHex, 4, 2));
        $b = hexdec(substr($cleanHex, 6, 2));
        return new self($a, $r, $g, $b);
    }
27782
function getDisplayHexColor() {
        $colorRole = $this->getColorRole();
        if($colorRole !== null && $colorRole->color > 0) {
            return $colorRole->hexColor;
        }
        
        return null;
    }
1333485
public function pass($asString = false)
    {
        if (!$this->_checked) {
            $this->check();
        }

        if (!$asString) {
            return $this->_pass;
        }

        $items = [];
        foreach ($this->_pass as $rule) {
            $items[] = "{$rule}";
        }

        return implode(', ', $items);
    }