小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

iso10646/unicode/utf8

 Ralf_Jones 2008-01-16
   ISO10646/Unicode規(guī)定了一套字符集,包含了世界上大多數(shù)常用字符,規(guī)定了這些字符的編碼。也就是說(shuō),每個(gè)字符會(huì)有一個(gè)規(guī)定好的編碼。

UTF8,UTF16,UTF32則規(guī)定了一套算法。根據(jù)各自的算法存儲(chǔ)ISO10646/Unicode的相應(yīng)字符。

[Edit UTF-8]

UTF-8


UTF-8的算法根據(jù)unicode字符的范圍而有變化,主要表現(xiàn)在存儲(chǔ)的字節(jié)數(shù)上,這是為了兼容ascii的單字節(jié)編碼。具體是這樣的:
0000-007F | 0xxxxxxx
0080-07FF | 110xxxxx 10xxxxxx
0800-FFFF | 1110xxxx 10xxxxxx 10xxxxxx
10000-10FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx

上面這個(gè)表里,字段1表示范圍,字段2表示編碼所使用的算法,或許稱為模板更為準(zhǔn)確。

例如有一個(gè)字符(汜),在unicode里的編碼為十六進(jìn)制的6C5C,范圍在0800-FFFF之間,所以取模板1110xxxx 10xxxxxx 10xxxxxx(也就是說(shuō),該字符為三字節(jié)的寬字符),該字符編碼換算成二進(jìn)制后代入模板,得1110[0110] 10[110001] 10[011100]。中括號(hào)里的數(shù)字,連接起來(lái)就是該字符的unicode編碼的二進(jìn)制表示。

下面是一個(gè)我寫(xiě)的把html的實(shí)體轉(zhuǎn)換為utf-8的函數(shù),編程語(yǔ)言為php。html的實(shí)體的其中一種格式為 &#unicode編碼的十進(jìn)制;,注意最后有個(gè)分號(hào)。
function htmlentity2utf8($string) {
    if (!preg_match("@&#(\d+);@",$string,$matches)) return $string;
    $he=$matches[1];
    $he=(int)$he;
    if ($he>=0x0000 && $he<=0x007f) {
        $template=array("0%");
    } elseif ($he>=0x0080 && $he<=0x007ff) {
        $template=array("110%","10%");
    } elseif ($he>=0x0800 && $he<=0xffff) {
        $template=array("1110%","10%","10%");
    } elseif ($he>=0x10000 && $he<=0x10ffff) {
        $template=array("11110%","10%","10%","10%");
    } else {
        return $string;
    }
    $template=array_reverse($template);
    $utf8=‘‘;
    $he_b=(string)sprintf("%b",$he);
    $offset=0;
    foreach ($template as $t) {
        $t_len=strlen($t);
        $need_count=9-$t_len;
        $offset-=$need_count;
          $current_he=substr(sprintf("%0".abs($offset)."s",$he_b),$offset,$need_count);
        $tmp=sprintf("%0".$need_count."d",$current_he);
        $utf8=chr(base_convert((str_replace(‘%‘,$tmp,$t)),2,10)).$utf8;
    }  
    return $utf8;
}
Config........0.00045204162597656 SECs
Instantiate..0.010334014892578 SECs
Render......3.3175349235535 SECs
This wiki is under GPL and the latest version can be found here.

iso10646

Navigator

KeyShortCuts

  • o - login/logout
  • e - edit
  • h - histories
  • v - recently views
  • m - recently modifies
  • w - go home
  • [ - go to previous
  • ] - go to next
  • u - lock/unlock
  • c - passwd
  • Accesskey(s) - save
  • AccessKey(c) - discard

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類(lèi)似文章 更多