Copy Code code as follows:
<?php
/********************************************
*
* Function Name: GET_UTF8_TO_GB ($value)
* Function: UTF8 encoded string into 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 the error, if a character in the conversion string has no corresponding character in the target character set, then the part after the character is ignored. That the result string content is incomplete, use the//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)
* Function: gb2312 encoded string into 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;
}
}
?>