Convert a single or multi-byte character to its code point

@param string $char
@return integer
973305
protected function charToCodePoint($char)
    {
        $code = ord($char[0]);
        if ($code < 128) {
            return $code;
        } elseif ($code < 224) {
            return (($code - 192) * 64) + (ord($char[1]) - 128);
        } elseif ($code < 240) {
            return (($code - 224) * 4096) + ((ord($char[1]) - 128) * 64) + (ord($char[2]) - 128);
        } else {
            return (($code - 240) * 262144) + ((ord($char[1]) - 128) * 4096) + ((ord($char[2]) - 128) * 64) + (ord($char[3]) - 128);
        }
    }
325412
public static function char2Unicode($char)
    {
        switch (strlen($char)) {
            case 1 :
                return ord($char);
            case 2 :
                return (ord($char{1}) & 63) |
                    ((ord($char{0}) & 31) << 6);
            case 3 :
                return (ord($char{2}) & 63) |
                    ((ord($char{1}) & 63) << 6) |
                    ((ord($char{0}) & 15) << 12);
            case 4 :
                return (ord($char{3}) & 63) |
                    ((ord($char{2}) & 63) << 6) |
                    ((ord($char{1}) & 63) << 12) |
                    ((ord($char{0}) & 7) << 18);
            default :
                trigger_error('Character is not UTF-8!', E_USER_WARNING);
                return false;
        }
    }
845173
public static function CHARACTER($character)
    {
        $character = PHPExcel_Calculation_Functions::flattenSingleValue($character);

        if ((!is_numeric($character)) || ($character < 0)) {
            return PHPExcel_Calculation_Functions::VALUE();
        }

        if (function_exists('mb_convert_encoding')) {
            return mb_convert_encoding('&#'.intval($character).';', 'UTF-8', 'HTML-ENTITIES');
        } else {
            return chr(intval($character));
        }
    }
275436
private function index(string $char): int {
        if (isset($this->index[$char])) {
            return $this->index[$char];
        }

        $this->index_count++;
        $this->index[$char] = $this->index_count;
        return $this->index_count;
    }
1037452
private static function unicodeChar($dec)
    {
        if ($dec < 0x80) {
            return chr($dec);
        }

        if ($dec < 0x0800) {
            return chr(0xC0 + ($dec >> 6))
                .chr(0x80 + ($dec & 0x3f));
        }

        if ($dec < 0x010000) {
            return chr(0xE0 + ($dec >> 12))
                    .chr(0x80 + (($dec >> 6) & 0x3f))
                    .chr(0x80 + ($dec & 0x3f));
        }

        if ($dec < 0x200000) {
            return chr(0xF0 + ($dec >> 18))
                    .chr(0x80 + (($dec >> 12) & 0x3f))
                    .chr(0x80 + (($dec >> 6) & 0x3f))
                    .chr(0x80 + ($dec & 0x3f));
        }
    }
1337301
protected function _charToCodePoint($char)
    {
        $code = ord($char[0]);
        if ($code < 128) {
            return $code;
        } elseif ($code < 224) {
            return (($code - 192) * 64) + (ord($char[1]) - 128);
        } elseif ($code < 240) {
            return (($code - 224) * 4096) + ((ord($char[1]) - 128) * 64) + (ord($char[2]) - 128);
        }
        return (($code - 240) * 262144) + ((ord($char[1]) - 128) * 4096) + ((ord($char[2]) - 128) * 64) + (ord($char[3]) - 128);
    }
1135072
public static function ord(string $char): int
    {
        if (\function_exists('\mb_ord')) {
            return \mb_ord($char);
        }

        $code = ($c = \unpack('C*', \substr($char, 0, 4))) ? $c[1] : 0;
        if (0xF0 <= $code) {
            return (($code - 0xF0) << 18) + (($c[2] - 0x80) << 12) + (($c[3] - 0x80) << 6) + $c[4] - 0x80;
        }
        if (0xE0 <= $code) {
            return (($code - 0xE0) << 12) + (($c[2] - 0x80) << 6) + $c[3] - 0x80;
        }
        if (0xC0 <= $code) {
            return (($code - 0xC0) << 6) + $c[2] - 0x80;
        }

        return $code;
    }
394472
protected function normalizeCharForKeyEvent($char) {
    if (!is_int($char) && !is_string($char)) {
      throw new DriverException("Unsupported key type, can only be integer or string");
    }

    if (is_string($char) && strlen($char) !== 1) {
      throw new DriverException("Key can only have ONE character");
    }

    $key = $char;
    if (is_int($char)) {
      $key = chr($char);
    }
    return $key;
  }
911166
static function toUTF8( $char_code )
    {
        switch ( $char_code )
        {
            case 0:
                $char = chr( 0 );
            case !($char_code & 0xffffff80): // 7 bit
                $char = chr( $char_code );
                break;
            case !($char_code & 0xfffff800): // 11 bit
                $char = ( chr(0xc0 | (($char_code >> 6) & 0x1f)) .
                          chr(0x80 | ($char_code & 0x3f)) );
                break;
            case !($char_code & 0xffff0000): // 16 bit
                $char = ( chr(0xe0 | (($char_code >> 12) & 0x0f)) .
                          chr(0x80 | (($char_code >> 6) & 0x3f)) .
                          chr(0x80 | ($char_code & 0x3f)) );
                break;
            case !($char_code & 0xffe00000): // 21 bit
                $char = ( chr(0xf0 | (($char_code >> 18) & 0x07)) .
                          chr(0x80 | (($char_code >> 12) & 0x3f)) .
                          chr(0x80 | (($char_code >> 6) & 0x3f)) .
                          chr(0x80 | ($char_code & 0x3f)) );
                break;
            case !($char_code & 0xfc000000): // 26 bit
                $char = ( chr(0xf8 | (($char_code >> 24) & 0x03)) .
                          chr(0x80 | (($char_code >> 18) & 0x3f)) .
                          chr(0x80 | (($char_code >> 12) & 0x3f)) .
                          chr(0x80 | (($char_code >> 6) & 0x3f)) .
                          chr(0x80 | ($char_code & 0x3f)) );
            default: // 31 bit
                $char = ( chr(0xfc | (($char_code >> 30) & 0x01)) .
                          chr(0x80 | (($char_code >> 24) & 0x3f)) .
                          chr(0x80 | (($char_code >> 18) & 0x3f)) .
                          chr(0x80 | (($char_code >> 12) & 0x3f)) .
                          chr(0x80 | (($char_code >> 6) & 0x3f)) .
                          chr(0x80 | ($char_code & 0x3f)) );
        }
        return $char;
    }
691587
private static function getCodePoint($char)
    {
        if ($char !== htmlspecialchars_decode(htmlspecialchars($char, ENT_COMPAT, 'UTF-8'))) {
            return 0xFFFD;
        }

        $x = ord($char[0]);

        if ($x < 0x80) {
            return $x;
        } elseif ($x < 0xE0) {
            $y = ord($char[1]);

            return (($x & 0x1F) << 6) | ($y & 0x3F);
        } elseif ($x < 0xF0) {
            $y = ord($char[1]);
            $z = ord($char[2]);

            return (($x & 0xF) << 12) | (($y & 0x3F) << 6) | ($z & 0x3F);
        }

        $y = ord($char[1]);
        $z = ord($char[2]);
        $w = ord($char[3]);

        return (($x & 0x7) << 18) | (($y & 0x3F) << 12) | (($z & 0x3F) << 6) | ($w & 0x3F);
    }
989093
protected static function crypt( $string, $key )
	{
		for( $i=0; $i<strlen( $string ); $i++ )
		{
			$char = ord( $string[$i] );
			if( $char > 64 && $char < 91 )
			{
				$char += $key;
				if( $char > 90 )
					$char -= 26;
				else if( $char < 65 )
					$char += 26;
			}
			else if( $char > 96 && $char < 123 )
			{
				$char += $key;
				if ($char > 122)
					$char -= 26;
				else if( $char < 97 )
					$char += 26;
			}
			$string[$i] = chr( $char );
		}
		return $string;
	}
1126215
public static function fromString($string)
	{
		$bits = new BitArray(strlen($string));
		$ord = 0;

		for ($offset = 0; $offset < $bits->size; $offset++)
		{
			if ($string[$offset] !== '0')
			{
				$ord |= 1 << $offset % 8;
			}

			if ($offset % 8 === 7)
			{
				$bits->data[(int) ($offset / 8)] = chr($ord);
				$ord = 0;
			}
		}

		if ($offset % 8 !== 0)
		{
			$bits->data[(int) ($offset / 8)] = chr($ord);
		}

		return $bits;
	}
1159659
private static function utf8chr(int $c): string
    {
        if (0x80 > $c %= 0x200000) {
            return \chr($c);
        }
        if (0x800 > $c) {
            return \chr(0xC0 | $c >> 6).\chr(0x80 | $c & 0x3F);
        }
        if (0x10000 > $c) {
            return \chr(0xE0 | $c >> 12).\chr(0x80 | $c >> 6 & 0x3F).\chr(0x80 | $c & 0x3F);
        }

        return \chr(0xF0 | $c >> 18).\chr(0x80 | $c >> 12 & 0x3F).\chr(0x80 | $c >> 6 & 0x3F).\chr(0x80 | $c & 0x3F);
    }
438994
public static function base64Decode($char)
    {
        if (!array_key_exists($char, self::$CHAR_TO_INT)) {
            throw new Exception("Not a valid base 64 digit: ".$char);
        }
        return self::$CHAR_TO_INT[$char];
    }
1054321
protected function getCharCode(string $chr):int{
		$i = \array_search($chr, $this::ALPHANUM_CHAR_MAP);

		if($i !== false){
			return $i;
		}

		throw new QRCodeDataException('illegal char: "'.$chr.'" ['.\ord($chr).']');
	}
768630
protected function compileCharacter($char)
    {
        switch (true) {
            case preg_match('(^U\\+[0-9a-fA-F]{4}$)', $char):
                return $this->converter->toUTF8Character(hexdec(substr($char, 2)));

            case preg_match('(^[0-9a-fA-F]{2}$)', $char):
                return chr(hexdec($char));

            default:
                throw new RuntimeException("Invalid character definition: $char");
        }
    }
930254
function hexNumber(char) {
    var code = char.toLowerCase().charCodeAt(0);
    // 0-9
    if (code >= 48 && code <= 57) {
      return code - 48;
    }
    // a-f
    if (code >= 97 && code <= 102) {
      return code - 87;
    }
    return code;
  }