From cdfb8894b999fc8aa6bf01e66c45ee0785101b13 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 1 Aug 2018 19:42:00 +0200 Subject: [PATCH] Add encoding change function --- System/File/FileUtils.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/System/File/FileUtils.php b/System/File/FileUtils.php index 9b044fe8b..d7b35825d 100644 --- a/System/File/FileUtils.php +++ b/System/File/FileUtils.php @@ -117,4 +117,23 @@ final class FileUtils return \realpath($origPath); } + + /** + * Change encoding of file + * + * @param string $file Path to file which should be re-encoded + * @param string $encoding New file encoding + * + * @return void + * + * @since 1.0.0 + */ + public static function changeFileEncoding(string $file, string $encoding) : void + { + $content = \file_get_contents($file); + + if ($content !== false && preg_match('!!u', $content)) { + \file_put_contents($file, \mb_convert_encoding($content, 'UTF-8', mb_list_encodings())); + } + } }