]> git.mxchange.org Git - friendica.git/blob - library/Smarty/libs/plugins/shared.mb_unicode.php
reverting tinymce changes, updating smarty to 3.1.19
[friendica.git] / library / Smarty / libs / plugins / shared.mb_unicode.php
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 {
22     if ($encoding) {
23         $expanded = mb_convert_encoding($string, "UTF-32BE", $encoding);
24     } else {
25         $expanded = mb_convert_encoding($string, "UTF-32BE");
26     }
27
28     return unpack("N*", $expanded);
29 }
30
31 /**
32  * convert unicodes to the character of given encoding
33  *
34  * @link   http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
35  *
36  * @param integer|array $unicode  single unicode or list of unicodes to convert
37  * @param string        $encoding encoding of returned string, if null mb_internal_encoding() is used
38  *
39  * @return string unicode as character sequence in given $encoding
40  * @author Rodney Rehm
41  */
42 function smarty_mb_from_unicode($unicode, $encoding = null)
43 {
44     $t = '';
45     if (!$encoding) {
46         $encoding = mb_internal_encoding();
47     }
48     foreach ((array) $unicode as $utf32be) {
49         $character = pack("N*", $utf32be);
50         $t .= mb_convert_encoding($character, $encoding, "UTF-32BE");
51     }
52
53     return $t;
54 }