Home > php教程 > php手册 > 关于BIG5-HKSCS的解决方法

关于BIG5-HKSCS的解决方法

WBOY
Release: 2016-06-13 12:31:50
Original
1094 people have browsed it

非常苦悶地發現,原來一直困擾的HKSCS問題PHP一直也支持。只不過名稱不叫HK-SCS,叫BIG5-HKSCS。
以下是HK增補字符集的解決方案:
HTML頁面設為UTF-8,
寫入數據庫前先:iconv('big5-hkscs','utf8', $string)
需轉為UNICODE就用以下函數
function String2Unicode($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;
}
function utf82unicode($c) {
 switch(strlen($c)) {
  case 1:
   return ord($c);
  case 2:
   $n = (ord($c[0]) & 0x3f)    $n += ord($c[1]) & 0x3f;
   return $n;
  case 3: 
   $n = (ord($c[0]) & 0x1f)    $n += (ord($c[1]) & 0x3f)    $n += ord($c[2]) & 0x3f;
   return $n;
  case 4:
   $n = (ord($c[0]) & 0x0f)    $n += (ord($c[1]) & 0x3f)    $n += (ord($c[2]) & 0x3f)    $n += ord($c[3]) & 0x3f;
   return $n;
 }
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template