Core File (UTF8 class) Utf8.php

Source: Internet
Author: User
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 );}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.