From efc8aa187ee659d6c03e3ae377fb7055d5bc450e Mon Sep 17 00:00:00 2001 From: NewEraCracker Date: Tue, 5 Apr 2016 15:50:57 +0100 Subject: [PATCH] Make translate_encoding generic Will make easier the implementation of marekrei#40 and later fixing of #37 --- index.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 21a3d2d..7aecd3e 100644 --- a/index.php +++ b/index.php @@ -2819,20 +2819,30 @@ function debug() } // - // Encode HTML output in correct encoding + // Encode output in correct encoding // - public static function translate_encoding($string) + public static function translate_encoding($string, $undo = false) { if(!is_string($string) || EncodeExplorer::getConfig('charset') == EncodeExplorer::getConfig('os_charset')) return $string; + if(!$undo) { + // From system encoding to output + $in = EncodeExplorer::getConfig('os_charset'); + $out = EncodeExplorer::getConfig('charset'); + } else { + // From input to system encoding + $in = EncodeExplorer::getConfig('charset'); + $out = EncodeExplorer::getConfig('os_charset'); + } + // Attempt using mb_convert_encoding if(function_exists('mb_convert_encoding')) - $tmp = @mb_convert_encoding($string, EncodeExplorer::getConfig('charset'), EncodeExplorer::getConfig('os_charset')); + $tmp = @mb_convert_encoding($string, $out, $in); // Attempt using iconv if(empty($tmp) && function_exists('iconv')) - $tmp = @iconv(EncodeExplorer::getConfig('os_charset'), EncodeExplorer::getConfig('charset'), $string); + $tmp = @iconv($in, $out, $string); // If any of them succeeds, return converted one if(!empty($tmp) && is_string($tmp))