Home >Backend Development >PHP Tutorial >Example of php Chinese character transcoding

Example of php Chinese character transcoding

WBOY
WBOYOriginal
2016-07-25 08:53:361092browse
  1. function unicode_encode($str, $encoding='gbk', $prefix='&#', $postfix=';'){
  2. $str = iconv($encoding, 'ucs-2', $str);
  3. $arrstr = str_split($str, 2);
  4. $unistr = '';
  5. for($i=0, $len=count($arrstr); $i<$len; $i++)
  6. {
  7. $dec = hexdec(bin2hex($arrstr[$i]));
  8. $unistr .= $prefix.$dec.$postfix;
  9. }
  10. return $unistr;
  11. } // bbs.it-home.org
  12. $str = '哈哈';
  13. $unistr = unicode_encode($str);
  14. echo $unistr.'
    ';
  15. ?>
复制代码


Statement:
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