note 100464 added to function.ord
| From: | swinefeaster/at | Date: | Mon, 18 Oct 2010 04:43:38 +0000 |
| Subject: | note 100464 added to function.ord | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173235@lists.php.net to get a copy of this message | ||
Thanks to Kerry for the ordUTF8 function. To make it even clearer, here's a function that calls
it and iterates through a UTF-8 string and spits out a unicode value for each decoded character of
the string:
function echoUnicodeCharsForUtf8String($input)
{
$output = "";
$len = strlen($input);
while($i < $len)
{
$character = substr($input, $i, 1);
$charNumBytes = 1;
$attempt = ordUTF8($input, $i, $charNumBytes);
echo "unicodeChar=" . $attempt . "<p>";//TODO
$i += $charNumBytes;
}
return $output;
}
// Kerry's function verbatim
function ordUTF8($c, $index = 0, &$bytes = null)
{
$len = strlen($c);
$bytes = 0;
if ($index >= $len)
return false;
$h = ord($c{$index});
if ($h <= 0x7F) {
$bytes = 1;
return $h;
}
else if ($h < 0xC2)
return false;
else if ($h <= 0xDF && $index < $len - 1) {
$bytes = 2;
return ($h & 0x1F) << 6 | (ord($c{$index + 1}) & 0x3F);
}
else if ($h <= 0xEF && $index < $len - 2) {
$bytes = 3;
return ($h & 0x0F) << 12 | (ord($c{$index + 1}) & 0x3F) << 6
| (ord($c{$index + 2}) & 0x3F);
}
else if ($h <= 0xF4 && $index < $len - 3) {
$bytes = 4;
return ($h & 0x0F) << 18 | (ord($c{$index + 1}) & 0x3F) << 12
| (ord($c{$index + 2}) & 0x3F) << 6
| (ord($c{$index + 3}) & 0x3F);
}
else
return false;
}
Check out CueBrain for learning languages on Android!
----
Server IP: 69.147.83.197
Probable Submitter: 24.85.238.109
----
Manual Page -- http://www.php.net/manual/en/function.ord.php
Edit -- https://master.php.net/note/edit/100464
Del: integrated -- https://master.php.net/note/delete/100464/integrated
Del: useless -- https://master.php.net/note/delete/100464/useless
Del: bad code -- https://master.php.net/note/delete/100464/bad+code
Del: spam -- https://master.php.net/note/delete/100464/spam
Del: non-english -- https://master.php.net/note/delete/100464/non-english
Del: in docs -- https://master.php.net/note/delete/100464/in+docs
Del: other reasons-- https://master.php.net/note/delete/100464
Reject -- https://master.php.net/note/reject/100464
Search -- https://master.php.net/manage/user-notes.php