PHP implementation Utf-8 and GB2312 encoding Mutual conversion function Code _php Tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
/********************************************
*
* Function Name: GET_UTF8_TO_GB ($value)
* Function: UTF8 encoded string converted 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 does not have a corresponding character in the target character set, then the part after that character is ignored. ; that is, the result string content is incomplete, and you want 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)
* Function: GB2312 encoded string converted 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;
}
}
?>

http://www.bkjia.com/PHPjc/326637.html www.bkjia.com true http://www.bkjia.com/PHPjc/326637.html techarticle Copy the code as follows:? PHP/******************************************** * * Function Name: GET_UTF8_TO_GB ($value) * for Using: UTF8 encoded string converted to GB2312 encoding * Author: ...

  • 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.