php汉字转码的例子
时间:2021-07-01 10:21:17
帮助过:17人阅读
- function unicode_encode($str, $encoding='gbk', $prefix='', $postfix=';'){
- $str = iconv($encoding, 'ucs-2', $str);
- $arrstr = str_split($str, 2);
- $unistr = '';
- for($i=0, $len=count($arrstr); $i<$len; $i++)
- {
- $dec = hexdec(bin2hex($arrstr[$i]));
- $unistr .= $prefix.$dec.$postfix;
- }
- return $unistr;
- } // bbs.it-home.org
- $str = '哈哈';
- $unistr = unicode_encode($str);
- echo $unistr.'
'; - ?>
|