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