PHP iconv mb_convert_encoding encoding conversion function _php Tutorial

Source: Internet
Author: User
With the Iconv function:

iconv ("Utf-8", "gb2312", "ABC Sunshine 123");

It is said that this is better, you can ignore the conversion error!

iconv ("Utf-8", "Gb2312//ignore", "ABC Sunshine 123");

Mb_convert_encoding's usage is in the official view:
http://cn.php Tutorial. net/manual/zh/function.mb-convert-encoding.php

Make a GBK to Utf-8

< PHP
Header ("content-type:text/html; Charset=utf-8 ");
Echo mb_convert_encoding ("My Friend", "Utf-8", "GBK");
?>

One more gb2312 to Big5.

< PHP
Header ("content-type:text/html; Charset=big5 ");
Echo mb_convert_encoding ("You Are my Friend", "Big5", "gb2312");
?>


However, to use the above function requires installation but first enable the mbstring extension library.

Another function in PHP, Iconv, is also used to convert string encodings, similar to functions on the upper function.

Here are a few more examples:
Iconv-convert string to requested character encoding
(PHP 4 >= 4.0.5, PHP 5)
Mb_convert_encoding-convert character encoding
(PHP 4 >= 4.0.6, PHP 5)

Usage:
String mb_convert_encoding (String str, string to_encoding [, mixed from_encoding])
Need to enable Mbstring expansion Library, in php.ini; Extension=php_mbstring.dll in front of; Remove
Mb_convert_encoding can specify a variety of input encoding, it will automatically identify according to the content, but the execution efficiency is much worse than the iconv;

http://www.bkjia.com/PHPjc/632355.html www.bkjia.com true http://www.bkjia.com/PHPjc/632355.html techarticle with the Iconv function: Iconv (utf-8, GB2312, ABC Sunshine 123); It is said that this is better, you can ignore the conversion error! Iconv (Utf-8, Gb2312//ignore, ABC Sunshine 123); The use of mb_convert_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.