Phpiconvmb_convert_encoding encoding conversion function

Source: Internet
Author: User
Use the iconv function: iconv (& quot; UTF-8 & quot;, & quot; gb2312 & quot;, & quot; abc Sunshine 123 & quot;); it is said that this is better, errors during conversion can be ignored! Iconv (& quot; UTF-8 & quot;, & quot; gb2312ignore & quot;

Use 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 ");

For the usage of mb_convert_encoding, refer to the official website:

Http://cn.php.net/manual/zh/function.mb-convert-encoding.php

Make a gbk to UTF-8

  1. Header ("content-type: text/html; charset = utf-8 ");
  2. Echo mb_convert_encoding ("my friends", "UTF-8", "gbk ");
  3. ?>

Another gb2312 to big5

  1. Header ("content-type: text/html; charset = big5 ");
  2. Echo mb_convert_encoding ("You are my friend", "big5", "gb2312 ");
  3. ?>

However, to use the above functions, you must install the enable mbstring Extension Library first. Another function iconv in php is also used to convert string encoding, similar to the function above.

The following are 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])

Enable mbstring extension Library first, and remove the extension library before extension = php_mbstring.dll in php. ini.

Mb_convert_encoding can specify multiple input encodings, which are automatically identified based on the content, but the execution efficiency is much lower than that of iconv;

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.