字符串转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 协议》,转载必须注明作者和本文链接