php--transcoding function

Source: Internet
Author: User

Recently in using dedecms two times to develop the membership function; everyone knows that DEDECMS encoding is GBK format; So in our project we often need to transcode, in my understanding there are two ways to transcode: first: iconv; second, mb_convert_encoding;

Here are the two ways to use the following transcoding methods:

Iconv

Iconv ("Utf-8″," GB2312 ", $string); convert $string from utf-8 encoding to GBK format

First parameter: The encoding format of the string now;

The second parameter: the encoding format that you want to convert;

The third parameter: the string you want to convert;

Mb_convert_encoding:

Mb_convert_encoding ($string, "Utf-8″," GBK "); convert $string from GBK to utf-8 format

{1. Need to enable Mbstring expansion library first

2.mb_convert_encoding can specify multiple input encodings, which are automatically recognized based on content, but perform more efficiently than iconv

}

First parameter: The string you want to convert;

The second parameter: the encoding format that you want to convert;

The third parameter: now the encoding format of the string;

The difference between Iconv and mb_convert_encoding two transcoding functions:

In fact, I use a knife this transcoding function is mainly in the member information export Excel format, when I add members when the transcoding to the database is iconv, but when I export Excel, I use Iconv, export some of the information may appear blank, so even a bug, but with Mb_ Convert_encoding When this is not the case, so I want to find out what the difference between the two functions I went to Baidu to see a bit;

This is what I found in Baidu is said:

The iconv is found to have an error converting the character "-" to gb2312, and if there is no ignore parameter, all strings after that character cannot be saved. In any case, this "-" can not be converted successfully, unable to output. Another mb_convert_encoding does not have this bug.
In general, with Iconv, only use the Mb_convert_encoding function if you encounter an inability to determine what encoding the original encoding is, or if the Iconv conversion fails to display properly.

So everyone in the use of the time to notice that you want to change the encoding format specific, so you know which is better use Ah!

php--transcoding function

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.