/** * Converts a single unicode character to the desired character set if possible. * Attempts to use iconv if it's available. * Callback function for the regular expression in convert_urlencoded_unicode. * * @param integer Unicode code point value * @param string Character to convert to * * @return string Character in desired character set or as an HTML entity */ function convert_unicode_char_to_charset($unicode_int, $charset) { $is_utf8 = (strtolower($charset) == 'utf-8'); if ($is_utf8) { return convert_int_to_utf8($unicode_int); } if (function_exists('iconv')) { // convert this character -- if unrepresentable, it should fail $output = @iconv('UTF-8', $charset, convert_int_to_utf8($unicode_int)); if ($output !== false AND $output !== '') { return $output; } } return "&#$unicode_int;"; }
/** * Converts a single unicode character to the desired character set if possible. * Attempts to use iconv if it's available. * Callback function for the regular expression in convert_urlencoded_unicode. * * @param integer Unicode code point value * @param string Character to convert to * * @return string Character in desired character set or as an HTML entity */ public static function convertUnicodeCharToCharset($unicode_int, $charset) { $is_utf8 = strtolower($charset) == 'utf-8'; if ($is_utf8) { return convert_int_to_utf8($unicode_int); } if (function_exists('iconv')) { // convert this character -- if unrepresentable, it should fail $output = @iconv('UTF-8', $charset, self::convertIntToUtf8($unicode_int)); if ($output !== false and $output !== '') { return $output; } } return "&#{$unicode_int};"; }