• ADADADADAD

    帝国CMS PHP汉字UTF-8转unicode码的方法![ 建站问答 ]

    建站问答 时间:2025-04-25 08:02:03

    作者:文/会员上传

    简介:

    php将汉字转unicode码就成了迫切需求。用搜索找到好多个函数,可惜在试用后都放弃了,这些函数只支持普通汉字的转码,对于生僻字不支持。只好自己写一个,测试成功了。这个函数是根

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    php将汉字转unicode码就成了迫切需求。用搜索找到好多个函数,可惜在试用后都放弃了,这些函数只支持普通汉字的转码,对于生僻字不支持。只好自己写一个,测试成功了。这个函数是根据unicode的二进制规则来写的。

    function dp_HzToUnicode($hz){ $r=array(); $hex=str_replace("%","",urlencode($hz)); $r['hex']=$hex; $bin2=base_convert($hex,16,2); $dec=base_convert($hex,16,10); if($dec<127){ $r['dec']=$dec; $r['unidoce']=$r['dec']; $r['bin2']=$bin2; return $r; } $bit=strlen($bin2)/8; $br=str_split($bin2,8); $true_bin2=''; for($i=0;$i<$bit;$i++){ if($i==0){ $true_bin2.=substr($br[$i],$bit+1); }else{ $true_bin2.=substr($br[$i],2); } } $r['bin2']=$true_bin2; $unidoce=base_convert($true_bin2,2,16); $r['unidoce']=$unidoce; $html=base_convert($true_bin2,2,10); $r['dec']=$html; return $r;}

    帝国CMS PHP汉字UTF-8转unicode码的方法!.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载
    热门标签: php