Phpiconvmb_convert_encoding encoding conversion function _ PHP Tutorial

Source: Internet
Author: User
Phpiconvmb_convert_encoding encoding conversion function. Use the iconv function: iconv (UTF-8, gb2312, abc Sunshine 123); it is said that this is better, you can ignore the error during conversion! Iconv (UTF-8, gb2312ignore, abc Sunshine 123); use the iconv function for mb_convert_encoding:

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 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 friends", "UTF-8", "gbk ");
?>

Another 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 functions, you need to install but 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;

Iconv (UTF-8, gb2312, abc Sunshine 123); it is said that this is better, you can ignore the error during conversion! Iconv (UTF-8, gb2312 // ignore, abc Sunshine 123); use 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.