fusionpbx/resources/templates/engine/smarty/plugins/shared.mb_unicode.php

52 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2013-11-09 21:02:56 +01:00
<?php
/**
* Smarty shared plugin
*
2018-11-07 08:18:14 +01:00
* @package Smarty
2013-11-09 21:02:56 +01:00
* @subpackage PluginsShared
*/
/**
* convert characters to their decimal unicode equivalents
*
2018-11-07 08:18:14 +01:00
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
*
2013-11-09 21:02:56 +01:00
* @param string $string characters to calculate unicode of
* @param string $encoding encoding of $string, if null mb_internal_encoding() is used
2018-11-07 08:18:14 +01:00
*
2013-11-09 21:02:56 +01:00
* @return array sequence of unicodes
* @author Rodney Rehm
*/
2018-11-07 08:18:14 +01:00
function smarty_mb_to_unicode($string, $encoding = null)
2013-11-09 21:02:56 +01:00
{
if ($encoding) {
2018-11-07 08:18:14 +01:00
$expanded = mb_convert_encoding($string, 'UTF-32BE', $encoding);
2013-11-09 21:02:56 +01:00
} else {
2018-11-07 08:18:14 +01:00
$expanded = mb_convert_encoding($string, 'UTF-32BE');
2013-11-09 21:02:56 +01:00
}
2018-11-07 08:18:14 +01:00
return unpack('N*', $expanded);
2013-11-09 21:02:56 +01:00
}
/**
* convert unicodes to the character of given encoding
*
2018-11-07 08:18:14 +01:00
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
*
2013-11-09 21:02:56 +01: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
2018-11-07 08:18:14 +01:00
*
2013-11-09 21:02:56 +01:00
* @return string unicode as character sequence in given $encoding
* @author Rodney Rehm
*/
2018-11-07 08:18:14 +01:00
function smarty_mb_from_unicode($unicode, $encoding = null)
2013-11-09 21:02:56 +01:00
{
$t = '';
if (!$encoding) {
$encoding = mb_internal_encoding();
}
2018-11-07 08:18:14 +01:00
foreach ((array)$unicode as $utf32be) {
$character = pack('N*', $utf32be);
$t .= mb_convert_encoding($character, $encoding, 'UTF-32BE');
2013-11-09 21:02:56 +01:00
}
return $t;
}