This article introduces the content of PHP iconv function to convert the code, such as UTF-8 to GB2312, has a certain reference value, now share to everyone, the need for friends can refer to
Recently in the construction of the construction Bank interface, it is necessary to convert the encoding UTF-8 to GB2312 so the Iconv function is used to convert the encoding.
found that only using the ICONV function to fetch the data of a transcoding data will be less for no reason. Let me depressed for a while, go online a check information to know this is a iconv function of a bug. Iconv error when converting character "-" to gb2312.
Let's take a look at the usage of this function.
The simplest application, replace the gb2312 into Utf-8:
$zhuan =iconv ("UTF-8", "GB2312", $data);
In the process of use, if you encounter some special characters, such as: "-", English name "." And so on character, the conversion is broken off. The text after these characters is not able to continue the conversion.
The following code can be implemented for this problem:
$zhuan =iconv ("UTF-8", "GBK", $data);
You have not read wrong, it is so simple, do not use gb2312, and write GBK, just can.
There is another way, the second argument, plus//ignore, ignores the error, as follows:
$zhuan =iconv ("UTF-8", "Gb2312//ignore", $data);
There is no specific comparison between the two methods, the feeling of the first (GBK instead of gb2312) method is better.