Php implements a function for mutual conversion between UTF-8 and GB2312 encoding. if you need it, refer
The code is as follows:
/*************************************** *****
*
* Function name: get_utf8_to_gb ($ value)
* Use: utf8 encoded string to gb2312 encoding
* Author: Liu Xianzhong
* Date: 2011-11-09
*
**************************************** ****/
Function get_utf8_to_gb ($ value ){
$ Value_1 = $ value;
$ Value_2 = @ iconv ("UTF-8", "gb2312 // IGNORE", $ value_1); // use @ to resist errors, if a character does not have a corresponding character in the target character set, the subsequent part of the character is ignored. that is, the result string is incomplete and you need to use // IGNORE
$ Value_3 = @ iconv ("gb2312", "UTF-8 // IGNORE", $ value_2 );
If (strlen ($ value_1) = strlen ($ value_3 ))
{
Return $ value_2;
} Else
{
Return $ value_1;
}
}
/*************************************** *****
*
* Function name: get_gb_to_utf8 ($ value)
* Use: gb2312 encoded string to utf8 encoding
* Author: Liu Xianzhong
* Date: 2011-11-09
*
**************************************** ****/
Function get_gb_to_utf8 ($ value ){
$ Value_1 = $ value;
$ Value_2 = @ iconv ("gb2312", "UTF-8 // IGNORE", $ value_1 );
$ Value_3 = @ iconv ("UTF-8", "gb2312 // IGNORE", $ value_2 );
If (strlen ($ value_1) = strlen ($ value_3 ))
{
Return $ value_2;
} Else
{
Return $ value_1;
}
}
?>