字符串转GBK编码

最靠谱的字符串转码

/**
 * 字符串转GBK编码
 * @param $strLong
 * @return string
 */
private function strToGBK($strLong)
{
    //获取其字符的内部数组表示,所以本文件应用utf-8编码!
    if (is_array($strLong)) {
        $arr = $strLong;
    } else {
        $word = iconv('utf-8', 'gbk', $strLong);
        $arr = str_split($word);
    }
    $bin_str = '';
    foreach ($arr as $value) {
        $bin_str .= '%'.dechex(bindec(decbin(ord($value))));
    }
    return $bin_str;
}

示例输入:

strToGBK(‘码’)

示例输出:

%C2%EB
本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!