以下是HK增補字符集的解決方案:
HTML頁面設為UTF-8,
寫入數據庫前先:iconv('big5-hkscs','utf8',$string)
需轉為UNICODE就用以下函數
functionString2Unicode($data,$language)
{
$data=nl2br(trim($data));
$data=str_replace('
',chr(13),$data);
$str='';
preg_match_all("/[x80-xff]?./",$data,$ar);
debug($ar);
foreach($ar[0]as$v)
{
if($v!=''&&$v!=chr(13))
{
$str.="".utf82unicode(iconv($language,"UTF-8",$v)).";";
}else{
$str.=$v;
}
}
return$str;
}
functionutf82unicode($c){
switch(strlen($c)){
case1:
returnord($c);
case2:
$n=(ord($c[0])&0x3f)<<6;
$n+=ord($c[1])&0x3f;
return$n;
case3:
$n=(ord($c[0])&0x1f)<<12;
$n+=(ord($c[1])&0x3f)<<6;
$n+=ord($c[2])&0x3f;
return$n;
case4:
$n=(ord($c[0])&0x0f)<<18;
$n+=(ord($c[1])&0x3f)<<12;
$n+=(ord($c[2])&0x3f)<<6;
$n+=ord($c[3])&0x3f;
return$n;
}
}