1 <?php
defined('SYSPATH') or die('No direct script access.');
7 * @copyright (c) 2007-2011 Kohana Team
8 * @copyright (c) 2005 Harry Fuecks
9 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
11 function _from_unicode($arr)
15 $keys = array_keys($arr);
19 // ASCII range (including control chars)
20 if (($arr[$k] >= 0) AND ($arr[$k] <= 0x007f))
25 elseif ($arr[$k] <= 0x07ff)
27 echo chr(0xc0 |
($arr[$k] >> 6));
28 echo chr(0x80 |
($arr[$k] & 0x003f));
30 // Byte order mark (skip)
31 elseif ($arr[$k] == 0xFEFF)
35 // Test for illegal surrogates
36 elseif ($arr[$k] >= 0xD800 AND $arr[$k] <= 0xDFFF)
39 throw new UTF8_Exception("UTF8::from_unicode: Illegal surrogate at index: ':index', value: ':value'", array(
45 elseif ($arr[$k] <= 0xffff)
47 echo chr(0xe0 |
($arr[$k] >> 12));
48 echo chr(0x80 |
(($arr[$k] >> 6) & 0x003f));
49 echo chr(0x80 |
($arr[$k] & 0x003f));
52 elseif ($arr[$k] <= 0x10ffff)
54 echo chr(0xf0 |
($arr[$k] >> 18));
55 echo chr(0x80 |
(($arr[$k] >> 12) & 0x3f));
56 echo chr(0x80 |
(($arr[$k] >> 6) & 0x3f));
57 echo chr(0x80 |
($arr[$k] & 0x3f));
62 throw new UTF8_Exception("UTF8::from_unicode: Codepoint out of Unicode range at index: ':index', value: ':value'", array(
69 $result = ob_get_contents();