public function _unicode_ord(&$c, &$i = 0)
{
// get the character length
$l = strlen($c);
// copy the offset
$index = $i;
// check it's a valid offset
if ($index >= $l) {
return false;
}
// check the value
$o = ord($c[$index]);
// if it's ascii
if ($o <= 0x7f) {
return $o;
// not sure what it is...
} elseif ($o < 0xc2) {
return false;
// if it's a two-byte character
} elseif ($o <= 0xdf && $index < $l - 1) {
$i += 1;
return ($o & 0x1f) << 6 | ord($c[$index + 1]) & 0x3f;
// three-byte
} elseif ($o <= 0xef && $index < $l - 2) {
$i += 2;
return ($o & 0xf) << 12 | (ord($c[$index + 1]) & 0x3f) << 6 | ord($c[$index + 2]) & 0x3f;
// four-byte
} elseif ($o <= 0xf4 && $index < $l - 3) {
$i += 3;
return ($o & 0xf) << 18 | (ord($c[$index + 1]) & 0x3f) << 12 | (ord($c[$index + 2]) & 0x3f) << 6 | ord($c[$index + 3]) & 0x3f;
// not sure what it is...
} else {
return false;
}
}