47 for($i = 0; $i < $len; $i++) {
55 if (0 == (0x80 & ($in))) {
60 }
else if (0xC0 == (0xE0 & ($in))) {
63 $mUcs4 = ($mUcs4 & 0x1F) << 6;
67 }
else if (0xE0 == (0xF0 & ($in))) {
70 $mUcs4 = ($mUcs4 & 0x0F) << 12;
74 }
else if (0xF0 == (0xF8 & ($in))) {
77 $mUcs4 = ($mUcs4 & 0x07) << 18;
81 }
else if (0xF8 == (0xFC & ($in))) {
91 $mUcs4 = ($mUcs4 & 0x03) << 24;
95 }
else if (0xFC == (0xFE & ($in))) {
98 $mUcs4 = ($mUcs4 & 1) << 30;
107 'utf8_to_unicode: Illegal sequence identifier '.
108 'in UTF-8 at byte '.$i,
119 if (0x80 == (0xC0 & ($in))) {
122 $shift = ($mState - 1) * 6;
124 $tmp = ($tmp & 0x0000003F) << $shift;
131 if (0 == --$mState) {
137 if (((2 == $mBytes) && ($mUcs4 < 0x0080)) ||
138 ((3 == $mBytes) && ($mUcs4 < 0x0800)) ||
139 ((4 == $mBytes) && ($mUcs4 < 0x10000)) ||
142 (($mUcs4 & 0xFFFFF800) == 0xD800) ||
144 ($mUcs4 > 0x10FFFF)) {
147 'utf8_to_unicode: Illegal sequence or codepoint '.
148 'in UTF-8 at byte '.$i,
156 if (0xFEFF != $mUcs4) {
173 'utf8_to_unicode: Incomplete multi-octet '.
174 ' sequence in UTF-8 at byte '.$i,
208 foreach (array_keys($arr) as $k) {
210 # ASCII range (including control chars)
211 if ( ($arr[$k] >= 0) && ($arr[$k] <= 0x007f) ) {
216 }
else if ($arr[$k] <= 0x07ff) {
218 echo chr(0xc0 | ($arr[$k] >> 6));
219 echo chr(0x80 | ($arr[$k] & 0x003f));
221 # Byte order mark (skip)
222 }
else if($arr[$k] == 0xFEFF) {
226 # Test for illegal surrogates
227 }
else if ($arr[$k] >= 0xD800 && $arr[$k] <= 0xDFFF) {
231 'utf8_from_unicode: Illegal surrogate '.
232 'at index: '.$k.
', value: '.$arr[$k],
239 }
else if ($arr[$k] <= 0xffff) {
241 echo chr(0xe0 | ($arr[$k] >> 12));
242 echo chr(0x80 | (($arr[$k] >> 6) & 0x003f));
243 echo chr(0x80 | ($arr[$k] & 0x003f));
246 }
else if ($arr[$k] <= 0x10ffff) {
248 echo chr(0xf0 | ($arr[$k] >> 18));
249 echo chr(0x80 | (($arr[$k] >> 12) & 0x3f));
250 echo chr(0x80 | (($arr[$k] >> 6) & 0x3f));
251 echo chr(0x80 | ($arr[$k] & 0x3f));
256 'utf8_from_unicode: Codepoint out of Unicode range '.
257 'at index: '.$k.
', value: '.$arr[$k],
266 $result = ob_get_contents();