source: trunk/include/smarty/libs/plugins/shared.mb_unicode.php @ 23485

Last change on this file since 23485 was 23485, checked in by rvelices, 11 years ago

Smarty EOL style LF svn property

  • Property svn:eol-style set to LF
File size: 1.5 KB
Line 
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 * @param string $string   characters to calculate unicode of
14 * @param string $encoding encoding of $string, if null mb_internal_encoding() is used
15 * @return array sequence of unicodes
16 * @author Rodney Rehm
17 */
18function smarty_mb_to_unicode($string, $encoding=null) {
19    if ($encoding) {
20        $expanded = mb_convert_encoding($string, "UTF-32BE", $encoding);
21    } else {
22        $expanded = mb_convert_encoding($string, "UTF-32BE");
23    }
24    return unpack("N*", $expanded);
25}
26
27/**
28 * convert unicodes to the character of given encoding
29 *
30 * @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
31 * @param integer|array $unicode  single unicode or list of unicodes to convert
32 * @param string        $encoding encoding of returned string, if null mb_internal_encoding() is used
33 * @return string unicode as character sequence in given $encoding
34 * @author Rodney Rehm
35 */
36function smarty_mb_from_unicode($unicode, $encoding=null) {
37    $t = '';
38    if (!$encoding) {
39        $encoding = mb_internal_encoding();
40    }
41    foreach((array) $unicode as $utf32be) {
42        $character = pack("N*", $utf32be);
43        $t .= mb_convert_encoding($character, $encoding, "UTF-32BE");
44    }
45    return $t;
46}
47
48?>
Note: See TracBrowser for help on using the repository browser.