將 UTF-8 零錯誤的轉換成 BIG5

yeahokay發表於2007-09-11
function ecstart_gbk_convert($buffer){
$slen=strlen($buffer);
$buffero=$buffer;
$buffer=iconv("gbk","big5",$buffer);
$olen=strlen($buffer);
if($slen != $olen)
{
$buffer=$buffer.ecstart_gbk2htmlunicode(substr($buffero,$olen,2)).ecstart_gbk_convert(substr($buffero,$olen+2));
}
return $buffer;
}

function ecstart_gbk2htmlunicode($buffer){
$len=strlen($buffer);
for($i=0;$i {
$h=ord($buffer[$i]);
if($h >= 0x81){
$tmpstr=iconv("gbk","utf16",$buffer[$i].$buffer[$i+1]);
$uni=hexdec(bin2hex($tmpstr[3].$tmpstr[2]));
$unicode .= "".$uni.";";
$i++;
}else{
$unicode .= $string[$i];
}
}
return $unicode;
}
function ecstart_utf8_convert($buffer){
$buffer=iconv("utf8","gbk",$buffer);
$buffer=ecstart_gbk_convert($buffer);
return $buffer;
}[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/786540/viewspace-968892/,如需轉載,請註明出處,否則將追究法律責任。

相關文章