PHP mb_convert_encoding Use

Source: Internet
Author: User

Mb_convert_encoding
  • (PHP 4 >= 4.0.6, PHP 5, PHP 7)
  • Mb_convert_encoding-convert character encoding
  • mb_convert_encoding-encoding of converted characters
Description
mb_convert_encoding($str,$to_encoding[,$from_encodingmb_internal_encoding()])//Converts the character encoding of string str to to_encoding from optionally from_encoding.
Parametersstr
    • The string being encoded.
    • The string to encode.
To_encoding
    • The type of encoding that STR was being converted to.
    • The type of encoding to which STR is to be converted.
From_encoding
    • is specified by character code names before conversion. It is the either an array, or a comma separated enumerated list. If from_encoding is not specified, the internal encoding would be used.
    • specified by the character code name before conversion. It can be an array or a comma-delimited list of enumerations. If from_encoding is not provided, the internal (internal) encoding is used.
Return Values
    • The encoded string.
    • The encoded string.
Examples
<?php/*** Created by Phpstorm.* User:zhangrongxiang* DATE:2018/1/28* Time: PM 10:34 */$str="Hello World\ n";/ * Convert internal character encoding to SJIS * /$str=mb_convert_encoding( $str, "SJIS" );Echo "1---".$str; //1---Hello world$str="Hello World\ n";/ * Convert euc-jp to UTF-7 * /$str=mb_convert_encoding( $str, "UTF-7", "EUC-JP" );Echo "2---".$str; //2---Hello world$str="Hello World\ n";/ * 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" );Echo "3---".$str; //3---Hello world$str="Hello World\ n";/ * "Auto" is expanded to "ascii,jis,utf-8,euc-jp,sjis" * /$str=mb_convert_encoding( $str, "EUC-JP", "Auto" );Echo "4---".$str; ///4---Hello world/** Traversal Character set * /$text="A Strange string to pass, maybe with some?,?,? Characters. Hello China ";foreach ( mb_list_encodings()  as $CHR ){/** other character sets converted to UTF-8 output * /    Echo $CHR.":".mb_convert_encoding( $text, ' UTF-8 ', $CHR ).Php_eol;    /**utf-8 conversion to other character set output * /    Echo $CHR.":".mb_convert_encoding( $text, $CHR, ' UTF-8 ' ).Php_eol;}/** Force Browser Output UTF-8 encoded String * /Header( "content-type:text/html; Charset=utf-8 " );//output valid before all outputsEcho mb_convert_encoding( "You're a good friend of mine.", "UTF-8", "GBK" );/** supported character encodings * ///ucs-4*//ucs-4be//ucs-4le*//ucs-2//ucs-2be//ucs-2le//utf-32*//utf-32be*//utf-32le*//utf-16*//utf-16be*//utf-16le*//utf-7//utf7-imap//utf-8*//ascii*//euc-jp*//sjis*//eucjp-win*//sjis-win*//ISO-2022-JP//iso-2022-jp-ms//cp932//cp51932//sjis-mac** (alias: Macjapanese)//sjis-mobile#docomo** (alias: Sjis-docomo)//sjis-mobile#kddi** (alias: Sjis-kddi)//sjis-mobile#softbank** (alias: Sjis-softbank)//utf-8-mobile#docomo** (alias: Utf-8-docomo)//utf-8-mobile#kddi-a**//utf-8-mobile#kddi-b** (alias: Utf-8-kddi)//utf-8-mobile#softbank** (alias: Utf-8-softbank)//iso-2022-jp-mobile#kddi** (alias: Iso-2022-jp-kddi)//jis//jis-ms//cp50220//cp50220raw//cp50221//cp50222//iso-8859-1*//iso-8859-2*//iso-8859-3*//iso-8859-4*//iso-8859-5*//iso-8859-6*//iso-8859-7*//iso-8859-8*//iso-8859-9*//iso-8859-10*//iso-8859-13*//iso-8859-14*//iso-8859-15*//iso-8859-16*//byte2be//byte2le//byte4be//byte4le//base64//html-entities//7bit//8bit//euc-cn*//cp936//gb18030**//hz//euc-tw*//cp950//big-5*//euc-kr*//UHC (CP949)//iso-2022-kr//windows-1251 (CP1251)//windows-1252 (CP1252)//cp866 (IBM866)//koi8-r*//koi8-u*//armscii-8 (ArmSCII8)//* indicates that the encoding can also be used in regular expressions. //* * indicates that the encoding is available from PHP 5.4.0. The value of "Auto" and "pass" can also be used for any php.ini entry that accepts an encoded name. The mbstring function that accepts the encoded name can also use the value "Auto". //If "pass" is set, the character encoding will not be converted. //If "Auto" is set, it expands to a list of each character encoding defined in the NLS. For example, assuming that the NLS is set to Japanese, the value will be considered "Ascii,jis,utf-8,euc-jp,sjis". 
Article reference
    • http://php.net/manual/en/function.mb-convert-encoding.php

PHP mb_convert_encoding Use

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.