/**
* 转编码为 gb2312
* @
param string $pStr 字符串
* @
param string $pCharset 字符串编码
*
* @
return string
*/
static function str2gbk($pStr, $pCharset) {
$tStr = '';
if ($pStr < 0x80) {
$tStr .= $pStr;
}
elseif ($pStr < 0x800) {
$tStr .= chr(0xC0 | $pStr >> 6);
$tStr .= chr(0x80 | $pStr & 0x3F);
}
elseif ($pStr < 0x10000) {
$tStr .= chr(0xE0 | $pStr >> 12);
$tStr .= chr(0x80 | $pStr >> 6 & 0x3F);
$tStr .= chr(0x80 | $pStr & 0x3F);
}
elseif ($pStr < 0x200000) {
$tStr .= chr(0xF0 | $pStr >> 18);
$tStr .= chr(0x80 | $pStr >> 12 & 0x3F);
$tStr .= chr(0x80 | $pStr >> 6 & 0x3F);
$tStr .= chr(0x80 | $pStr & 0x3F);
}
return iconv($pCharset, 'GB2312', $tStr);
}