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