2011-09-16 14:19:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Smarty shared plugin
|
|
|
|
*
|
2014-06-06 02:40:04 +00:00
|
|
|
* @package Smarty
|
2011-09-16 14:19:56 +00:00
|
|
|
* @subpackage PluginsShared
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* convert characters to their decimal unicode equivalents
|
|
|
|
*
|
2018-06-12 09:58:15 +02:00
|
|
|
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
2011-09-16 14:19:56 +00:00
|
|
|
* @param string $string characters to calculate unicode of
|
|
|
|
* @param string $encoding encoding of $string, if null mb_internal_encoding() is used
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
2011-09-16 14:19:56 +00:00
|
|
|
* @return array sequence of unicodes
|
|
|
|
* @author Rodney Rehm
|
|
|
|
*/
|
2014-06-06 02:40:04 +00:00
|
|
|
function smarty_mb_to_unicode($string, $encoding = null)
|
2013-07-14 22:15:45 +00:00
|
|
|
{
|
2011-09-16 14:19:56 +00:00
|
|
|
if ($encoding) {
|
2017-11-06 01:02:56 +01:00
|
|
|
$expanded = mb_convert_encoding($string, 'UTF-32BE', $encoding);
|
2011-09-16 14:19:56 +00:00
|
|
|
} else {
|
2017-11-06 01:02:56 +01:00
|
|
|
$expanded = mb_convert_encoding($string, 'UTF-32BE');
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
2013-07-14 22:15:45 +00:00
|
|
|
|
2017-11-06 01:02:56 +01:00
|
|
|
return unpack('N*', $expanded);
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* convert unicodes to the character of given encoding
|
|
|
|
*
|
2018-06-12 09:58:15 +02:00
|
|
|
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
2011-09-16 14:19:56 +00:00
|
|
|
* @param integer|array $unicode single unicode or list of unicodes to convert
|
|
|
|
* @param string $encoding encoding of returned string, if null mb_internal_encoding() is used
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
2011-09-16 14:19:56 +00:00
|
|
|
* @return string unicode as character sequence in given $encoding
|
|
|
|
* @author Rodney Rehm
|
|
|
|
*/
|
2014-06-06 02:40:04 +00:00
|
|
|
function smarty_mb_from_unicode($unicode, $encoding = null)
|
2013-07-14 22:15:45 +00:00
|
|
|
{
|
2011-09-16 14:19:56 +00:00
|
|
|
$t = '';
|
|
|
|
if (!$encoding) {
|
|
|
|
$encoding = mb_internal_encoding();
|
|
|
|
}
|
2013-07-14 22:15:45 +00:00
|
|
|
foreach ((array) $unicode as $utf32be) {
|
2017-11-06 01:02:56 +01:00
|
|
|
$character = pack('N*', $utf32be);
|
|
|
|
$t .= mb_convert_encoding($character, $encoding, 'UTF-32BE');
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
2013-07-14 22:15:45 +00:00
|
|
|
|
2011-09-16 14:19:56 +00:00
|
|
|
return $t;
|
|
|
|
}
|