Fixed PHP 8.2 utf8_encode deprecated in Charset.php
authorraortegar <raquel.ortega@moodle.com>
Tue, 31 Jan 2023 13:37:34 +0000 (14:37 +0100)
committerraortegar <raquel.ortega@moodle.com>
Tue, 31 Jan 2023 13:37:34 +0000 (14:37 +0100)
src/Helper/Charset.php

index d683140..447eaa0 100644 (file)
@@ -253,7 +253,11 @@ class Charset
             case 'ISO-8859-1_UTF-8':
                 $escapedData = str_replace(array('&', '"', "'", '<', '>'), array('&amp;', '&quot;', '&apos;', '&lt;', '&gt;'), $data);
                 /// @todo if on php >= 8.2, prefer using mbstring or iconv. Also: suppress the warning!
-                $escapedData = utf8_encode($escapedData);
+                if (function_exists('mb_convert_encoding')) {
+                        $escapedData = mb_convert_encoding($escapedData, 'UTF-8', 'ISO-8859-1');
+                } else {
+                    $escapedData = utf8_encode($escapedData);
+                }
                 break;
 
             case 'ISO-8859-1_US-ASCII':