關(guān)于BIG5-HKSCS的解決方法
更新時間:2007年03月20日 00:00:00 作者:
非常苦悶地發(fā)現(xiàn),原來一直困擾的HKSCS問題PHP一直也支持。只不過名稱不叫HK-SCS,叫BIG5-HKSCS。
以下是HK增補字符集的解決方案:
HTML頁面設為UTF-8,
寫入數(shù)據(jù)庫前先:iconv('big5-hkscs','utf8', $string)
需轉(zhuǎn)為UNICODE就用以下函數(shù)
function String2Unicode($data, $language)
{
$data = nl2br(trim($data));
$data = str_replace('<br />',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) << 6;
$n += ord($c[1]) & 0x3f;
return $n;
case 3:
$n = (ord($c[0]) & 0x1f) << 12;
$n += (ord($c[1]) & 0x3f) << 6;
$n += ord($c[2]) & 0x3f;
return $n;
case 4:
$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;
}
}
以下是HK增補字符集的解決方案:
HTML頁面設為UTF-8,
寫入數(shù)據(jù)庫前先:iconv('big5-hkscs','utf8', $string)
需轉(zhuǎn)為UNICODE就用以下函數(shù)
function String2Unicode($data, $language)
{
$data = nl2br(trim($data));
$data = str_replace('<br />',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) << 6;
$n += ord($c[1]) & 0x3f;
return $n;
case 3:
$n = (ord($c[0]) & 0x1f) << 12;
$n += (ord($c[1]) & 0x3f) << 6;
$n += ord($c[2]) & 0x3f;
return $n;
case 4:
$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;
}
}
相關(guān)文章
解決出現(xiàn)SoapFault (looks like we got no XML document)的問題
下面小編就為大家?guī)硪黄鉀Q出現(xiàn)SoapFault (looks like we got no XML document)的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06PDO版本問題 Invalid parameter number: no parameters were bound
發(fā)現(xiàn)在客戶的某個PHP版本下,執(zhí)行某類操作的時候,總是會報如下錯誤 Invalid parameter number: no parameters were bound,經(jīng)google,發(fā)現(xiàn)是php版本過低導致2013-01-01PHP中使用localhost連接Mysql不成功的解決方法
這篇文章主要介紹了PHP中使用localhost連接Mysql不成功的解決方法,但使用127.0.0.1則沒有問題,本文也可以說是對連接MySQL主機使用127.0.0.1與localhost的區(qū)別的講解,需要的朋友可以參考下2014-08-08六酷社區(qū)論壇HOME頁清新格調(diào)免費版 下載
六酷社區(qū)論壇HOME頁清新格調(diào)免費版 下載...2007-03-03