Move mbstring/iconv configuration and MB_ENABLED, ICONV_ENABLED out of CI_Utf8::__construct()
Also, use mb_substitute_character() instead of ini_set()
diff --git a/system/core/Utf8.php b/system/core/Utf8.php
index b58c611..6ca1a02 100644
--- a/system/core/Utf8.php
+++ b/system/core/Utf8.php
@@ -48,42 +48,10 @@
*/
public function __construct()
{
- log_message('debug', 'Utf8 Class Initialized');
-
- $charset = strtoupper(config_item('charset'));
-
- // set internal encoding for multibyte string functions if necessary
- // and set a flag so we don't have to repeatedly use extension_loaded()
- // or function_exists()
- if (extension_loaded('mbstring'))
- {
- define('MB_ENABLED', TRUE);
- mb_internal_encoding($charset);
- // This is required for mb_convert_encoding() to strip invalid characters
- ini_set('mbstring.substitute_character', 'none');
- }
- else
- {
- define('MB_ENABLED', FALSE);
- }
-
- // Do the same for iconv, which actually has more easy to remember
- // predefined constants (such as ICONV_IMPL), but the iconv PHP
- // manual page says that using them is "strongly discouraged".
- if (extension_loaded('iconv'))
- {
- define('ICONV_ENABLED', TRUE);
- iconv_set_encoding('internal_encoding', $charset);
- }
- else
- {
- define('ICONV_ENABLED', FALSE);
- }
-
if (
defined('PREG_BAD_UTF8_ERROR') // PCRE must support UTF-8
&& (ICONV_ENABLED === TRUE OR MB_ENABLED === TRUE) // iconv or mbstring must be installed
- && $charset === 'UTF-8' // Application charset must be UTF-8
+ && strnatcasecmp(config_item('charset'), 'UTF-8') === 0 // Application charset must be UTF-8
)
{
define('UTF8_ENABLED', TRUE);
@@ -94,6 +62,8 @@
define('UTF8_ENABLED', FALSE);
log_message('debug', 'UTF-8 Support Disabled');
}
+
+ log_message('debug', 'Utf8 Class Initialized');
}
// --------------------------------------------------------------------