<?php
/**
* @version $Id$
* @package utf8
* @subpackage strings
*/
//---------------------------------------------------------------
/**
* UTF-8 aware alternative to ord
* Returns the unicode ordinal for a character
* @param string UTF-8 encoded character
* @return int unicode ordinal for the character
* @see http://www.php.net/ord
* @see http://www.php.net/manual/en/function.ord.php#46267
*/
function utf8_ord($chr) {
$ord0 = ord($chr);
if ( $ord0 >= 0 && $ord0 <= 127 ) {
return $ord0;
}
if ( !isset($chr{1}) ) {
trigger_error('Short sequence - at least 2 bytes expected, only 1 seen');
return FALSE;
}
$ord1 = ord($chr{1});
if ( $ord0 >= 192 && $ord0 <= 223 ) {
return ( $ord0 - 192 ) * 64
+ ( $ord1 - 128 );
}
if ( !isset($chr{2}) ) {
trigger_error('Short sequence - at least 3 bytes expected, only 2 seen');
return FALSE;
}
$ord2 = ord($chr{2});
if ( $ord0 >= 224 && $ord0 <= 239 ) {
return ($ord0-224)*4096
+ ($ord1-128)*64
+ ($ord2-128);
}
if ( !isset($chr{3}) ) {
trigger_error('Short sequence - at least 4 bytes expected, only 3 seen');
return FALSE;
}
$ord3 = ord($chr{3});
if ($ord0>=240 && $ord0<=247) {
return ($ord0-240)*262144
+ ($ord1-128)*4096
+ ($ord2-128)*64
+ ($ord3-128);
}
if ( !isset($chr{4}) ) {
trigger_error('Short sequence - at least 5 bytes expected, only 4 seen');
return FALSE;
}
$ord4 = ord($chr{4});
if ($ord0>=248 && $ord0<=251) {
return ($ord0-248)*16777216
+ ($ord1-128)*262144
+ ($ord2-128)*4096
+ ($ord3-128)*64
+ ($ord4-128);
}
if ( !isset($chr{5}) ) {
trigger_error('Short sequence - at least 6 bytes expected, only 5 seen');
return FALSE;
}
if ($ord0>=252 && $ord0<=253) {
return ($ord0-252) * 1073741824
+ ($ord1-128)*16777216
+ ($ord2-128)*262144
+ ($ord3-128)*4096
+ ($ord4-128)*64
+ (ord($chr{5})-128);
}
if ( $ord0 >= 254 && $ord0 <= 255 ) {
trigger_error('Invalid UTF-8 with surrogate ordinal '.$ord0);
return FALSE;
}
}
| nama | waktu | ukuran | owner | perm | aksi |
|---|---|---|---|---|---|
| .. | |||||
| mbstring/ | 2013-02-26 20:16 | 4.13 KB | 76129f60960:kunden | dxwrx-rx-r | |
| native/ | 2013-02-26 20:16 | 16.63 KB | 76129f60960:kunden | dxwrx-rx-r | |
| utils/ | 2013-02-26 20:16 | 52.66 KB | 76129f60960:kunden | dxwrx-rx-r | |
| LICENSE | 2013-02-26 20:15 | 25.81 KB | 76129f60960:kunden | -xw-x----- | |
| README | 2013-02-26 20:15 | 3.29 KB | 76129f60960:kunden | -xw-x----- | |
| index.html | 2013-02-26 20:15 | 31 B | 76129f60960:kunden | -xw-x----- | |
| ord.php | 2013-02-26 20:15 | 2.35 KB | 76129f60960:kunden | -xw-x----- | |
| str_ireplace.php | 2013-02-26 20:15 | 1.95 KB | 76129f60960:kunden | -xw-x----- | |
| str_pad.php | 2013-02-26 20:15 | 1.67 KB | 76129f60960:kunden | -xw-x----- | |
| str_split.php | 2013-02-26 20:15 | 824 B | 76129f60960:kunden | -xw-x----- | |
| strcasecmp.php | 2013-02-26 20:15 | 546 B | 76129f60960:kunden | -xw-x----- | |
| strcspn.php | 2013-02-26 20:15 | 894 B | 76129f60960:kunden | -xw-x----- | |
| stristr.php | 2013-02-26 20:15 | 855 B | 76129f60960:kunden | -xw-x----- | |
| strrev.php | 2013-02-26 20:15 | 458 B | 76129f60960:kunden | -xw-x----- | |
| strspn.php | 2013-02-26 20:15 | 923 B | 76129f60960:kunden | -xw-x----- | |
| substr_replace.php | 2013-02-26 20:15 | 600 B | 76129f60960:kunden | -xw-x----- | |
| trim.php | 2013-02-26 20:15 | 2.18 KB | 76129f60960:kunden | -xw-x----- | |
| ucfirst.php | 2013-02-26 20:15 | 787 B | 76129f60960:kunden | -xw-x----- | |
| ucwords.php | 2013-02-26 20:15 | 1.44 KB | 76129f60960:kunden | -xw-x----- | |
| utf8.php | 2013-02-26 20:15 | 2.22 KB | 76129f60960:kunden | -xw-x----- | |