The main function of the UTF8 class is to check whether the CI and environment support Utf8 encoding, conversion encoding, and string filtering functions:/*** Utf8Class */classCI_Utf8 {/*** structure
The main function of the UTF8 class is to check whether the CI and environment support Utf8 encoding, conversion encoding, and string filtering:
/*** Utf8 Class */class CI_Utf8 {/*** constructor: checks whether utf8 */function _ construct () {log_message ('debug ', "Utf8 Class Initialized"); global $ CFG; if (preg_match ('/. /U', ''') = 1 // regular support UTF-8AND function_exists ('iconv') // iconv installed AND ini_get ('mbstring. func_overload ')! = 1 // multibyte string function overload not enabled AND $ CFG-> item ('charset') = 'utf-8' // Configure the charsetUTF-8) {log_message ('debug', "UTF-8 Support Enabled"); define ('utf8 _ enabled', TRUE ); // 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 ('utf-8 '); // set the internal encoding} else {define ('MB _ enabled', FALSE);} else {log_message ('debug', "UTF-8 Support Disabled "); define ('utf8 _ enabled', FALSE);} // Encode/*** filter the UTF8 string because the success rate of encoding conversion is not 100% */function clean_string ($ str) {if ($ this-> _ is_ascii ($ str) == FALSE) {// IGNORE indicates that if the string is not converted to a UTF-8, it is replaced by a similar string, otherwise, if the string cannot be cut, E_NOTICE $ str = @ iconv ('utf-8', 'utf-8 // IGNORE ', $ str);} return $ str ;} // ----------------------------------------------------------------------/*** remove invisible characters in the string to avoid xml parsing errors [excluding line breaks, carriage returns, and horizontal tabs, use common. remove_invisible_characters function in php] */function safe_ascii_for_xml ($ str) {return remove_invisible_characters ($ str, FALSE );} // Convert/*** convert the string to UTF-8 encoding */function convert_to_utf8 ($ str, $ encoding) {if (function_exists ('iconv ')) {$ str = @ iconv ($ encoding, 'utf-8', $ str);} elseif (function_exists ('MB _ convert_encoding ')) {$ str = @ mb_convert_encoding ($ str, 'utf-8', $ encoding);} else {return FALSE;} return $ str ;} /*** check whether the string is ASCII code */function _ is_ascii ($ str) {return (preg_match ('/[^ \ x00-\ x7F]/S', $ str) = 0 );}}