PHP Chinese encoding Conversion mb_convert_encoding () function _php Tutorial

Source: Internet
Author: User
Coding in PHP has always been a headache for developers, but if the sweet some useful functions are different, let's introduce a processing function for a Chinese encoding.

Mb_convert_encoding ($str, $encoding 1, $encoding 2)

$str, to convert the encoded string
$encoding 1, the target code, such as UTF-8,GBK, is case-sensitive
$encoding 2, the original code, such as UTF-8,GBK, case can be

Example 1

The code is as follows Copy Code

$str = ' movie 618:http://www.bkjia.c0m ';
Echo mb_convert_encoding ($str, "UTF-8"); Convert Encoding to Utf-8
?>

Example 2

The code is as follows Copy Code

$str = ' movie 618:http://www.bkjia.c0m ';
Echo mb_convert_encoding ($str, "UTF-8", "GBK"); Known original encoded as GBK, converted to Utf-8
?>

Example 3

The code is as follows Copy Code

$str = ' movie 618:http://www.bkjia.c0m ';
Echo mb_convert_encoding ($str, "UTF-8", "Auto"); Unknown original code, after auto auto-detection, the conversion code is UTF-8
?>

Php.net Site Instance

The code is as follows Copy Code

/* Convert internal character encoding to SJIS */
$str = mb_convert_encoding ($str, "SJIS");

/* Convert EUC-JP to UTF-7 */
$str = mb_convert_encoding ($str, "UTF-7", "EUC-JP");

/* Auto detect encoding from JIS, Eucjp-win, Sjis-win, then convert str to Ucs-2le */
$str = mb_convert_encoding ($str, "Ucs-2le", "JIS, Eucjp-win, Sjis-win");

/* "Auto" is expanded to "ascii,jis,utf-8,euc-jp,sjis" */
$str = mb_convert_encoding ($str, "EUC-JP", "Auto");
?>

http://www.bkjia.com/PHPjc/632258.html www.bkjia.com true http://www.bkjia.com/PHPjc/632258.html techarticle Coding in PHP has always been a headache for developers, but if the sweet some useful functions are different, let's introduce a processing function for a Chinese encoding. ...

  • 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.