From a5b4893bb0524b5cd899589ee992c31807b3b5bd Mon Sep 17 00:00:00 2001 From: Andrew Rudenets <andrey.rudenets@gmail.com> Date: Wed, 28 Oct 2015 12:16:57 +0300 Subject: [PATCH] Added check the current encoding of the file --- ~dev_rating/application/classes/FileParser.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/~dev_rating/application/classes/FileParser.php b/~dev_rating/application/classes/FileParser.php index ea5ea2fce..18df0d806 100644 --- a/~dev_rating/application/classes/FileParser.php +++ b/~dev_rating/application/classes/FileParser.php @@ -109,6 +109,12 @@ class FileParser public static function toUTF8($source_str) { // TODO: make it able to convert from any encoding to UTF-8 - return mb_convert_encoding($source_str, "utf-8", "windows-1251"); + $enc = mb_detect_encoding($source_str, mb_list_encodings(), true); + if ($enc === false) + return $source_str; + else if ($enc !== "UTF-8") + return mb_convert_encoding($source_str, "utf-8", "windows-1251"); + else + return $source_str; } } -- GitLab