Created
September 1, 2017 21:48
-
-
Save masakielastic/9307344d9cee3d0c35829cd84cf2f60a to your computer and use it in GitHub Desktop.
utf8_ord
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 utf8_ord($char) { | |
$x = ord($char[0]); | |
if ($x < 0x80) { | |
return $x; | |
} else if ($x < 0xE0) { | |
$y = ord($char[1]); | |
return (($x & 0b11111) << 6) + ($y & 0b111111); | |
} else if ($x < 0xF0) { | |
$y = ord($char[1]); | |
$z = ord($char[2]); | |
return (($x & 0b1111) << 12) + (($y & 0b111111) << 6) + ($z & 0b111111); | |
} | |
$y = ord($char[1]); | |
$z = ord($char[2]); | |
$w = ord($char[3]); | |
return (($x & 0b1111) << 18) + (($y & 0b111111) << 12) + (($z & 0b111111) << 6) + ($w & 0b111111); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment