Home > Backend Development > PHP Tutorial > 找了一个中文转化UNICODE底的函数_PHP

找了一个中文转化UNICODE底的函数_PHP

WBOY
Release: 2016-06-01 12:36:17
Original
1088 people have browsed it

// GB2312 转换为 unicode 的函数  
// Program by sadly (www.phpx.com)

function gb2unicode($gb)
{
  if(!trim($gb))
   return $gb;
  $filename="gb2312.txt";
  $tmp=file($filename);
  $codetable=array();
  while(list($key,$value)=each($tmp))
   $codetable[hexdec(substr($value,0,6))]=substr($value,9,4);
  $utf="";
  while($gb)
  {
   if (ord(substr($gb,0,1))>127)
    {
    $this=substr($gb,0,2);
    $gb=substr($gb,2,strlen($gb));
    $utf.="".$codetable[hexdec(bin2hex($this))-0x8080].";";
    }
   else
    {
    $gb=substr($gb,1,strlen($gb));
    $utf.=substr($gb,0,1);
    }
   }
  return $utf;
}
?>

但是我没有gb2312码表,哪位能提供一份啊?

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template