equal
deleted
inserted
replaced
|
1 <?php |
|
2 /** |
|
3 * Smarty shared plugin |
|
4 * |
|
5 * @package Smarty |
|
6 * @subpackage PluginsShared |
|
7 */ |
|
8 |
|
9 /** |
|
10 * convert characters to their decimal unicode equivalents |
|
11 * |
|
12 * @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration |
|
13 * |
|
14 * @param string $string characters to calculate unicode of |
|
15 * @param string $encoding encoding of $string, if null mb_internal_encoding() is used |
|
16 * |
|
17 * @return array sequence of unicodes |
|
18 * @author Rodney Rehm |
|
19 */ |
|
20 function smarty_mb_to_unicode($string, $encoding = null) { |
|
21 if ($encoding) { |
|
22 $expanded = mb_convert_encoding($string, "UTF-32BE", $encoding); |
|
23 } else { |
|
24 $expanded = mb_convert_encoding($string, "UTF-32BE"); |
|
25 } |
|
26 |
|
27 return unpack("N*", $expanded); |
|
28 } |
|
29 |
|
30 /** |
|
31 * convert unicodes to the character of given encoding |
|
32 * |
|
33 * @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration |
|
34 * |
|
35 * @param integer|array $unicode single unicode or list of unicodes to convert |
|
36 * @param string $encoding encoding of returned string, if null mb_internal_encoding() is used |
|
37 * |
|
38 * @return string unicode as character sequence in given $encoding |
|
39 * @author Rodney Rehm |
|
40 */ |
|
41 function smarty_mb_from_unicode($unicode, $encoding = null) { |
|
42 $t = ''; |
|
43 if (!$encoding) { |
|
44 $encoding = mb_internal_encoding(); |
|
45 } |
|
46 foreach ((array)$unicode as $utf32be) { |
|
47 $character = pack("N*", $utf32be); |
|
48 $t .= mb_convert_encoding($character, $encoding, "UTF-32BE"); |
|
49 } |
|
50 |
|
51 return $t; |
|
52 } |